pesartain.com

where I remind myself what I've accomplished.

Handy Bash Scripts

Coming from a background of scripting rather than real programming, I found Bash scripting incredibly handy for automating tasks that, although not complex, required long wait times or large quantities of files.

Using the .bashrc to alias these scripts will give you your very own programmable commands! That's likely for another discussion …

Azureus Decapitated

- run the java BitTorrent client Azureus without a GUI (headless).

These are the instructions for running Azureus from the command line, and setting up a web interface. The script just basically allows me to run it simply. It's two lines, but it's my two lines.

#!/bin/bash
 
cd /usr/local/azureus/
java -jar Azureus2.jar --ui=console

Fixed point calculator

#!/bin/bash
 
echo $(($1));

To use:

user@Melchior:~/scripts$ ./calc.sh
0
user@Melchior:~/scripts$ ./calc.sh 1+2
3
user@Melchior:~/scripts$ ./calc.sh 2*3
6
user@Melchior:~/scripts$ ./calc.sh 1/2
0
user@Melchior:~/scripts$ ./calc.sh 2/2
1

It does not deal with decimal places, but I have it aliased as “calc”, so I can run it from anywhere for quick sums when I'm tired ;)

Downloaded files archive

Purchasing CDs is always cheaper than purchasing new hard drives, so I back up files that could be hard to find again (old versions of stuff, tricky drivers to locate on the support site, etc). Backing up is all well and good, but you need an index to find the files again! This uses a MySQL database for the record store, and a text file named /etc/security/mpswd to store the password. The file is plain text and locked down to anybody but my user, so it's semi-secure.

The script accepts one argument and must be edited directly to point to your downloads folder. Unlike many of the other scripts, this does not deal recursively with directories!

Download

Massive recusive chmod command

Take a look at the “File Permissions” section of the Win2Lin article for the problem that this was developed to solve.

Running it with the argument -h shows how to use the file. $permissions must be the 3-finger 8-bit numerical permissions string to properly operate on the directories, while options may be any other options usually applied to chmod.

user@Melchior:~/scripts$ ./massfileset.sh -h
Usage: massfileset.h [ -h | $/top/level/dir $permissions $options ]

      -h                      This message
      $/top/level/dir         The directory you wish to recurse into
      $permissions            The permission string
      $options                Any other options

Download

Music Database

This is a rather user-unfriendly MP3 archival system that uses a MySQL database to support it. I've been told Perl is better at doing this, but, I'm quite proud of my Bash script!

Developed from an ASP/Access project, this is now being moved to a Java environment (see the kerpow project) to provide a basic cross-platform archival tool.

Running with -h shows the options the program uses.

user@Melchior:~/scripts$ ./music.sh -h    
Usage:
music.sh -[u|a|h|A|r]
-u      Current list of unarchived things.
-a      Complete list of music.
-h      This help message.
-A      Archive music folder.
-r      Check for unused album/artists.''

Download

Note: The database would have to be set up by hand, making this script useless for anyone except as a point of reference for connecting a database to a bash script.

run - a program launcher

Usage instructions & download

The script itself is titled “run”, and is mostly used to run games under Wine/Cedega on a new X client, but also works well with native Linux games. Since I've now helped more than a few people with getting dual-monitors up and running, I've started working on making run a little easier to setup, and thus given it it's own page.

Aliasing run in .bashrc allows you to execute the script from anywhere in your directory tree. Handy.

user@Melchior:~/scripts$ ./run -h

Usage: run [ -p #no | -l | -a | -h ]

      -p              Play game #no
      -l              List current games (Human readable)
      -a              List current games (Path details)
      -h              This message''

System file backup

Just copies a bunch of system files that were likely to have been user-modified at some time or another to a backup location. Useful for quick backups when you're wiping the system.

Download

Who am I? I answer to Piete or Pieter and I try to be more than just my job title.

Browse my blog, read about me, or listen to my music.