Skip to main content

8 posts tagged with "bash"

View All Tags

gpx2tcx Shell Script

· 6 min read
gpx2tcx.sh screenshot

Following on from my gpx2tcx AWK script and Windows batch file, I now present what will probably the last separate component in the series... my gpx2tcx.sh Bash shell script.

This script is similar in nature to the Windows equivalent presented earlier, however it is considerably more flexible. Unlike the Windows batch file, this Bash script supports a number of command line arguments that allow its operation to be tweaked more easily.

svn: No newline at end of file

· 4 min read
Subversion logo

If you've used Subversion for any significant length of time, then you've probably run into the following message (or one just like it), near the end of a svn diff command.

\ No newline at end of file

Of course, you would have realised that this is because your editor has added a newline character to the end of the file in question, where the original had no such newline character.

Getting binary LOBs from DB2 via the command line

· 4 min read
IBM DB2 logo

Sometimes you just want to extract a single BLOB from a DB2 database... you don't want to write any software... you don't want to pull out some scripting language with a true DB2 database driver binding... you just want to get a BLOB from the database, and write it to a file - using nothing but the command line.

Well, there are two ways, that I know of, to do so. The first one, is the officially "correct" method, and should always work. The second method is even easier, but only works for very small BLOBs (which is all you need sometimes).

Finding the local IP address with ifconfig and sed

· 3 min read

There are many ways to determine local IP addresses on Linux platforms. They almost always involve piping ifconfig into a number of grep, awk, cat, and/or tr commands.

Well, my new favorite approach is to pipe ifconfig into a single sed command :)

ifconfig | sed -n -e 's/:127\.0\.0\.1 //g' -e 's/ *inet addr:\([0-9.]\+\).*/\1/gp'

Neat, huh?! :)

So, how does it work? Well, there are two filters (aka scripts, ie the parameters after the -e flags). The first one, 's/:127\.0\.0\.1 //g', simply strips out all occurrences of the local loopback address (127.0.0.1) - this can be left out if you want to include the loopback address in the results. And the second filter, 's/ *inet addr:\([0-9.]\+\).*/\1/gp' matches all lines with IP addresses, strips all but the IP address itself, and prints the matching line (note the p at the end of the filter, which works in with the -n flag at the start of the sed command).

Signing S3 HTTP upload policies via the command line

· 2 min read

When creating HTTP web forms to allow browser-based uploads to an S3 bucket, you need to create and sign upload policies. Now if that statement lost you, then you should read over either of the following introductions to browser-based uploads to S3:

Never trust a bunny!!

· One min read

Ok, I screwed up!! I was playing with an xargs command in order to process, then delete, some files. Since I was still "developing" the command, I was simply echo'ing the commands rather than running them... here's what I ran...

ls -1 | xargs -I{} bash -c 'echo cat {} /usr/local/bin/catchmail.sh ; rm {}'

Trusting imported GPG keys

· 2 min read

I had to export a GPG key from one Linux host to another today. While that is not something that's particularly difficult, it is one of those tasks that I do frequently enough to be worth remembering, but not enough to actually remember. So, it makes sense to document the process somewhere, and since it may help others, here it is ;)