Shell scripting

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."

Automatized backup of files and directories

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.

Automatized backup of MySQL databases

I was given the task to write a script that makes daily backups of our company's MySQL databases and keeps only the most recent <n> of them (where <n> is a positive integer Eye-wink ). This is not a big deal for anyone with some knowledge of shell scripting, but I publish it nonetheless, because I think the implementation is quite nice and might spare some minutes/hours for beginners.

Implementing "--parent" switch of the Linux "cp" command in a Windows batch script

The point of the "--parent" switch is to copy a file (or a directory) with it's parent directory structure to another directory. This is not exactly a trivial task in a Windows batch file and as such, it's a great opportunity to introduce some not very widespread features of the command prompt (eg. setlocal/endlocal, the "&" command separator, string operations).

Did I already mention that Windows sux? Sad
Batch scripting is so clumsy ... you have to write dozens of lines to get something that you can do within one line in any standard Unix/Linux shell. Shocked

Syndicate content