Restarting Individual Services or the Entire HDP Stack in the Hortornworks Virtual Sandbox

I’m using the Hortonworks Virtual Sandbox for development and testing and wanted to restart the HDP stack without (of course) having to restart the VM.

It took me a little while to figure out how to go about it as Internet searches on the topic revealed very little.

It turns out that Hortonworks have set up their own service on the box, startup_script.

If you take a look at /etc/init.d/startup_script you will see that it calls a number of other → Continue reading “Restarting Individual Services or the Entire HDP Stack in the Hortornworks Virtual Sandbox”

Vim Search and Replacing with Backreferences

It is often helpful to write search and replace commands that save segments of the matched text to use in the replacement string.

Source text:

This is some text (we want to change) with a phone number (301) 555-1234.
We want to remove the parenthesis, but only from the phone number string.

In this example we have a text file that has a phone number in it and we want to remove the parenthesis that surround ONLY the area code → Continue reading “Vim Search and Replacing with Backreferences”

Print Lines in a File From a Specific Line Number Until the End of the File with sed

If you know that you want all of the lines in a given file from n to EOF the following is the sed command:

sed -n '3,$p' some_file.txt

To print out lines 2 – 5 simply modify it to:

sed -n '2,5p' some_file.txt

Continue reading “Print Lines in a File From a Specific Line Number Until the End of the File with sed”

Removing the Last Token From a String in Bash with awk

Let’s say that you have some number of files for which you want to create a containing directory that is named with all but the last token of the file name, and you want to remove just the last token to create the name of the directory.

Much easier to explain with an example.  Given this list of files:

ls -1
foo_10_10_sometrash
foo_1_sometrash
foo_2_sometrash
foo_3_sometrash
foo_4_sometrash
foo_5_5_sometrash
foo_5_sometrash
foo_6_6_sometrash
foo_7_7_sometrash
foo_8_8_sometrash
foo_9_9_sometrash

You want to create a directory for each → Continue reading “Removing the Last Token From a String in Bash with awk”

Backspace, Delete, and/or Return Key Stops Working in Oracle SQL Developer

So, I fire up SQL Developer to run some queries against a QC server and for some reason, I am no longer able to use the backspace, delete, or return keys to edit .sql files opened in the program.

I tried opening a new .sql file, and restarting SQL Developer.  I then tried restarting Windows.  None of those worked.

After a bit of searching I found a forum posting that indicated by going to Tools/Preferences/Accelerators and clicking the “Load Preset…” → Continue reading “Backspace, Delete, and/or Return Key Stops Working in Oracle SQL Developer”

Checking that Input or a Variable is an Integer in BASH

Here is a quick snippet for checking whether or not a variable is a valid integer in BASH.  It is also a howto for regular expressions in a shell script.

# Make sure that FOO is an integer
if [[ ! "$FOO" =~ ^[0-9]+$ ]]; then
        echo "The FOO was NOT an integer"
fi
Continue reading “Checking that Input or a Variable is an Integer in BASH”

How To Benchmark Disk I/O

Here is a quick snipped on how to benchmark Disk I/O with dd.

time sh -c "dd if=/dev/zero of=/home/rchapin/test.zeros bs=1024k count=10000 && sync"

10000+0 records in
10000+0 records out
10485760000 bytes (10 GB) copied, 81.4124 s, 129 MB/s

real    1m21.950s
user    0m0.810s
sys     0m5.474s

Will do a write test of 10GB.

You can do a similar test and read from that file generated and write to another file or /dev/null to get an idea of the read speeds.

See the → Continue reading “How To Benchmark Disk I/O”

Creating an Array in Bash from a File With Each Element on a Separate Line

Let’s say that you have a file and you would like to convert each line in the file to an element in an array.

The key to this is knowing about and how to manipulate the IFS (Internal Field Separator).  The default IFS is whitespace (a space, tab, or newline) and if you create an array passing it a whitespace delimited list of strings, each token will be set to an element in the array.

ARRAY=(a b d 
Continue reading “Creating an Array in Bash from a File With Each Element on a Separate Line”

Installing Chrome Extensions Without Signing in With a Google Account

Google requires that you login with a Google account before you can install any Chrome extensions.

The following is how to install an extension without logging in (under Windows.  The same should work under Linux and Mac):

  1. Find the ID for the extension.  When you browse the extension in the store you will see a URL similar to the following:  https://chrome.google.com/webstore/detail/cookies/iphcomljdfghbkdcfndaijbokpgddeno?hl=en.   The hash string after the ‘cookies’ string (the name of the extension) up to the ? is the
Continue reading “Installing Chrome Extensions Without Signing in With a Google Account”