Assorted Scripts

This is just a bunch of random scripts that make various tasks (hopefully) easier. More will be added as they're written. Note that, unlike the main projects, no real documentation exists and they have not been tested on a variety of platforms.

ansi2html.pl | backup_mailer.py | dvd2iso.sh | gcalc | remote_pipe.pl

This takes plain text from standard input and converts it in to HTML that replicates the original format as closely as possible. Some ANSI formatting codes are supported, namely bold and foreground colours. The exact colours used to render the ANSI are determined by the selected palette. Tab alignment is also supported. Usage information is:

ansi2html.pl [ -h ] [ -p ]

    -h    Displays this message
    -p    Sets the palette used to render ANSI colours

    Available palettes: none normal dark

For example, "ls -l /usr/local/realplayer/ | ansi2html.pl -p dark" produces:

total 770
drwxr-sr-x  2  501  501     48 Oct  4 13:57 Bin
-rw-r--r--  1  501  501  11286 Sep 25 01:57 LICENSE
-rw-r--r--  1  501  501   3021 Sep 25 01:57 README
drwxr-sr-x  2  501  501    416 Sep 25 01:57 codecs
drwxr-sr-x  2  501  501    112 Sep 25 01:57 common
drwxr-sr-x  2  501  501     48 Sep 25 01:57 doc
-rw-r--r--  1 root root  22048 Oct  4 13:57 install.log
drwxr-sr-x  2  501  501     80 Sep 25 01:57 lib
drwxr-sr-x  2  501  501   1648 Sep 25 01:57 plugins
-rwxr-xr-x  1  501  501   2481 Oct  4 13:57 realplay
-rwxr-xr-x  1  501  501 734383 Sep 25 01:57 realplay.bin
drwxr-sr-x  6  501  501    408 Sep 25 01:57 share

The HTML it produces is fairly simplistic, consisting of <tt>, <font>, <br /> tags and HTML entities. The output is only a fragment with no HTML header or footer, not even a surround paragraph or blockquote tag.

Download here - right clicking and selecting 'Save As' may be required.

This emails a file to a given address as a MIME encoded attachment. The file can be split across multiple messages to prevent it breaking attachment size limits and the messages can be spaced out over a period of time to avoid overloading a server. SMTP and POP3 authentication are supported. Usage information is:

backup_mailer.py -f FILE -t TO_ADDR -s FROM_ADDR -h MAIL_SERVER
                 -b BYTES_PER_MSG -d DELAY_SECS [ -p POPUSER:POPPASS ]
                 [ -a SMTPUSER:SMTPPASS ]

    -f x    File to backup
    -t x    Email address to send backup message(s) to
    -s x    Email address to use in 'From:' field
    -h x    Mail server to use
    -b x    Maximum size of attachment in each message
    -d x    Delay between messages in seconds
    -p x:y  Perform POP3 authentication using this uid/pwd, colon seperated
    -a x:y  Perform SMTP authentication using this uid/pwd, colon seperated

    If a password field (in -p and -a) is empty then the user will be
    prompted to enter the password.

    Both POP3 authentication (if used) will be done before each message
    (i.e. each segment of the file) is sent.

The script was designed to make it easy to backup a given file to an email account, a kind of low budget offsite backup. The script does not encrypt or compress the file, this should be done using your standard compression/encryption application. For example, if you wanted to backup the file example.tar to backup@somemail.com using the authenticating mail.somemail.com SMTP server which only accepts 1MB attachments you might use:

$ gpg --recipient your@address.com --output example.tar.gpg --encrypt example.tar
$ backup_mailer.py -f example.tar.gpg -t backup@somemail.com -s your@address.com
  -h mail.somemail.com -b 1048576 -d 0 -a youruser:
  Please enter SMTP password for mail.somemail.com:

Note that if you omit the SMTP password the script will prompt you to enter it. The same is true of POP3 authentication.

Files that have been split across multiple messages can be recombined by downloading the attachments at cating them together.

Download here - right clicking and selecting 'Save As' may be required.

This is simply a wrapper around lsdvd, dvdbackup and mkisofs. It was written so a DVD could be backed up to an ISO image with one command. Note that the copy is not transcoded, reduced in size or otherwise altered - the copy is the same size as the original. The usage information is:

dvd2iso.sh -o output_iso_path [ -d dvd_device ]

The path of the output ISO is mandatory but the DVD device switch can be left off if your setup matches the default of /dev/dvd.

Download here - right clicking and selecting 'Save As' may be required.

Gentoo Users - the packages required to use this are lsdvd, dvdbackup and dvdrtools.

A simple command-line interface to the Google Calculator. The string following gcalc is passed to the Google website and the response is displayed on standard out. Note that only calculator responses will be displayed, search results are ignored; also it may be necessary to put the query in quotes as certain mathematical symbols (e.g. asterisk, brackets, exclamtion mark) are processed as commands by the shell.

Simple examples:

$ gcalc "1 + 2 * 3"
1 + (2 * 3) = 7
$ gcalc 1000 rods in nautical miles
1 000 rods = 2.71555076 nautical miles
$ gcalc random string
Google Calculator did not understand : random string
$ gcalc 41000 yen in british pounds
41 000 Japanese yen = 202.771962 British pounds

By quoting the query it is possible to submit more complex calculations (below). See the Google Calculator guide for a full description of what the Google Calculator supports.

$ gcalc "(speed of light / 2) in feet per second"
the speed of light / 2 = 491 785 528 feet per second
$ gcalc "( the 5th root of pi * 100 mod 0x10 ) + 0b101 "
(((5th root of pi) * 100) modulo 0x10) + 0b101 = 18.7274116

Download here - right clicking and selecting 'Save As' may be required.

Note that gcalc requires Python 2.3 or above.

This is a very simple version of netcat that just moves bytes from one instance's standard input, over a network connection, and to another instance's standard output. As it's written in Perl the script should run on pretty much any OS and communication between different platforms isn't an issue.

Using the script is trivial. Simply setup the listener instance on one machine, and then run the sender instance on another. Once the sender has consumed all the available standard input and sent it on to the listener, both instances will terminated. The usage information is

remote_pipe.pl -p PORT [ -h -l -b SIZE -t HOST -e ]

    -h    Displays this message
    -p    The port on which to listen/send
    -t    The hostname of the target server
    -b    Message buffer size, in bytes
    -l    Listen for incoming file
    -e    Append EOF to transmission
    -c    When sending data, calculate throughput and display on stderr

The script can be used in place of a normal pipe operator. For example, to concatenate multiple files to an output file on a different machine ...

remote_machine$ remote_pipe.pl -p 1234 -l > output_file.txt
local_machine $ cat file1.txt file2.txt | remote_pipe.pl -p 1234 -t remote_machine

Combined with tar the script can be used for fast directory tree transfers ...

remote_machine$ remote_pipe.pl -p 1234 -l | tar xfj -
local_machine $ tar cfj - some_directory | remote_pipe.pl -p 1234 -t remote_machine

Download here - right clicking and selecting 'Save As' may be required.