Posts tagged ‘script’

I often find myself changing routes on my OS X system. Usually, however, I’m systematically adding the same routes over and over again, because they were automatically removed after a reboot, network change or whatever. Enter LocationChanger.

Continue reading ‘Automatically doing things when you change network’ »

I regularly watch log files in real time using the highly appreciated tail -f command. But I usually find myself manually inserting newlines to give a visual clue of which log-lines happened together. Obviously the timestamps in the lines tell you the full story, but it’s not that visually appealing.

Continue reading ‘Tail-ing logfiles with visual timing’ »

dd-wrt has built-in support for a whole list of Dynamic DNS services. Unfortunately, they only support HTTP-based services. I use a standard RFC2136 DNS update. Here’s how to add nsupdate support to dd-wrt.

Continue reading ‘Using nsupdate in dd-wrt’ »

As mentioned, my new ESC also has data-logging capabilities. The provided software actually has a fairly descend viewer, but it lacks some features.

Continue reading ‘ESC data logging’ »

SSH is a wonderful tool. It allows you to run commands on a remote host, either manually, or from scripts. Obviously, since it’s a remote connection, you must authenticate yourself to the remote host. There are several ways of doing this.

When using SSH in a script, most pages tell you to use public keys. While this is an excellent idea, it’s sometimes just not possible due to policy. This Expect script fakes a regular username-password login

#!/usr/bin/expect -f

set target [lindex $argv 0]
set password [lindex $argv 1]
set command [lindex $argv 2]

spawn ssh $target $command

match_max 100000
# Look for passwod prompt
expect “*?assword:*”
# Send password aka $password
send — “$password\r”
# send blank line (\r) to make sure we get back to gui
send — “\r”
expect eof

This script can be run like this:

./ssh-passwd.ex root@192.0.2.1 password “ls /root”

Sometimes it’s really useful to prepend a timestamp to every output line of a command. This can be done fairly easily:

$command | \
perl -pe '@now=localtime();printf "%04d-%02d-%02dT%02d:%02d:%02d ",$now[5]+1900,$now[4]+1,$now[3],$now[2],$now[1],$now[0];'

The perl command reads in every line, prints the current time in the default format (or in whatever format you specify), followed by the read line.

ssh-to-puttyssh-to-puttyIn Windows you can register “url handlers”. These are programs that are run when you try to open a URL (via Start->Run for example). “http://” for example is registered to Internet Explorer by default. “telnet://” also works. This is especially useful in combination with the URL-field of KeePass. Double-clicking on this field tries to “open” the specified URL.

However, “ssh://” is not a standard registered protocol. I’d like Putty to handle this. Also, “telnet://” gets you the standard windows telnet client instead of putty. Putty can be called with command line arguments. Supplying the “telnet://” url as a parameter works, but “ssh://” does not.

Hence, I wrote a very small wrapper program to accept “ssh://” URL’s and convert them to Putty command line arguments:

  • Source code in C: ssh-to-putty.c
  • Compiled Windows executable: ssh-to-putty.exe (some virus-scanners seem to think this is a virus, exe is no longer available, please compile it yourself)
  • Registry commands to set putty as telnet-handler: putty telnet url handler.reg
  • Registry commands to set the wrapper as ssh-handler: putty ssh url handler.reg

Some notes:

  • The registry commands assume Putty and the wrapper are installed in C:\Progs\SSH. If this is not the case, you need to change the .reg-files accordingly
  • The wrapper-program assumes putty.exe to be in the same directory as itself

I was looking for an easy way to parse a binary file. I know what the file contains (it’s an MPEG2 transport stream) and know the bit-field layout. It’s just a pain to figure the bits out manually in a hex editor.

Google pointed me to 010 Editor which supports binary templates, which is pretty much what I was looking for. However, this tool only runs on Windows and is commercial. Enough reason to look further.

That’s when I came across the Data::ParseBinary perl module, which is a true relief to use. It supports pretty much every thing you need to parse a binary file:

  • Signed and unsigned integers
  • Big and little endian
  • 8, 16, 32 and 64 bit integers
  • Bitfields
  • Enum-types to specify your own names for values
  • If-constructs: Fields are present or not depending on the value of another field

In short, an incredible tool!

rsync is a very nice tool to synchronize two directories, especially if they are on different machines. If you require confidentiality of the transferred data, rsync works great over ssh.

Besides the standard password authentication, ssh also supports public key authentication. This key-based authentication has the added bonus of having per-key options:

  • you can restrict the source IP from which this key may be used
  • you can force a command to be executed instead of allowing the connecting side to specify one

Continue reading ‘Restricted rsync over ssh’ »

I got another toy to play with: A digital multimeter with RS232 interface and True RMS power measurement. Sadly, it comes with Windows-only software, which I interpreted as a challenge!

Continue reading ‘VoltCraft VC-940 protocol reverse engineered’ »