Shell scripting

Mozilla (Firefox + Thunderbird) profile cleaner for linux

It happens occasionally that after a crash (Firefox/Thunderbird or the PC itself) starting up Firefox (or Thunderbird) you experience weird behaviour. Eg. it tells you that the app is already running or it starts, but bookmarks are not available, etc. Cleaning your profile can be easily done manually by removing a couple of files in your Firefox/TB profile, but average users are not familiar with contents of these profile folders. To help them I've written a small app (shell script using Zenity to provide a GUI) that you can put in your Gnome/KDE/etc. menu so all your users can easily access it. Of course, you're free to customize the script anyway you like (eg. take out a few questions to make it even more automatic). I've tested the script in Ubuntu 9.10 (Firefox 3.5.9 and Thunderbird 2.0.0.24).

Various set operations (union, intersection, difference) on two text files

I didn't know about the comm command. It's the ideal solution to generate the "set symmetric difference" of two text files.

Regular calls to Drupal cron.php scripts on a server with a number of Drupal sites

Calling the cron.php of a Drupal site is fairly easy. You just have to put something similiar into your server's /etc/crontab:
0 * * * * www-data test -x /usr/bin/wget && /usr/bin/wget --bind-address 127.0.0.1 -t 1 "http://example.com/cron.php"
Or you can place this wget call in a file in /etc/cron.hourly.

However on a server with quite some Drupal sites (and possibly a number of virtualhosts) the maintenance of these cron.php calls in your crontab becomes very annoying (and it is prone to errors). On a busy development server Drupal sites come and go every day. So why not do these calls automatically? The attached script does just that. Smiling

Running a script on logout from Gnome

There's a nice Python script for the job at linuxquestions.org written by Seamus Phelan. I've tested it, found a few problems and fixed them.

Gtkdialog - complex GUI for scripts

"Gtkdialog is a small utility for fast and easy GUI building. It can be used to create dialog boxes for almost any interpreted and compiled programs which is a very attractive feature since the developer does not have to learn various GUI languages for the miscellaneous programming languages."

Gtkdialog is not just a simple xdialog replacement like Zenity. It allows creation of complex GUI with event-driven controlling logic. The GUI layout is described in XML files. Quite fancy. Smiling

Zenity - Gtk+ dialogs for shell scripts

Just found out about this: "Zenity is a tool that allows you to display Gtk+ dialog boxes from the command line and through shell scripts. It is similar to gdialog, but is intended to be saner. It comes from the same family as dialog, Xdialog, and cdialog, but it surpasses those projects by having a cooler name." Seems to be pretty useful. The original project homepage is at GNOME Live.

Automatized online backup of MySQL databases using LVM snapshots

This is again a script that people could write easily if they understood some shell scripting, but it is quite well implemented with logging and all and maybe spares a couple of minutes/hours of your time. Smiling

You should use it with crontab on a daily basis. For details take a look at the desc. of the MySQL backup script.

Redirecting standard output (stdout) to standard error (stderr)

Some might find this trivial, but it was not trivial to me. If you want to print something to stderr in a shell script, you can redirect the output of a command (eg. echo) to this stream (file handle or whatever):
echo "text" >&2

Fixing stty errors during crontab scripts on HP-UX

By default if you run crontab scripts on a HP-UX machine, you might get error messages like this:
ttytype: couldn't open /dev/tty for reading
stty: : Not a typewriter
Not a terminal

How to decide about a variable whether it contains a number or not

Let's suppose we have a variable named myvar. How do you decide (in a safe way!) in a standard POSIX shell (or in the almost equivalent /bin/sh of the Debian distros) whether it contains a number or not? Sounds pretty much trivial, not? Here's what I came up with:
mynumber=_
mynumber=$(($myvar)) 2> /dev/null
{ [ "$mynumber" = "_" ] && echo "Myvar is not a number."; } || echo "Myvar is a number."

Syndicate content