The Countdown on the homepage of this site (update: no longer used) is produced by using a script, run from the crontab. Thanks to a few folks on a certain irc channel for getting me past some mental blocks.

In cron, there is an entry which reads

*/15 * * * * ~/path/to/countdown ~/path/to/datafile > ~/path/to/outputfile

Countdown is shown below, it is a text file chmodded to 755. The datafile is a simple text file with the format

2006-11-23 :: Event Details 2006-12-14 14:23 :: Other Event 2005-09-23 :: \<a href\=\"\"\>Go and look at Murk's Amazon Wishlist\</a\>

The times are optional, note that anything which BASH may misinterpret should be escaped, i.e. prefixed with /

The resulting file can be put into a webpage using a server side include, or some other means.

The data file will automatically be sorted into date order when the script is run. Please note that the script isn't really set up for repeating events. If anyone modifies the script to do this, I would be pleased to learn of the mod.

At some point, I want to limit it to the next N events only, this should be a simple modification, but I don't have the will right now! The script should not display events more than 24 hours old, nor should it display events more than a year hence (actually, it is a little less than a year)

I would also like to be able to specify when the item should appear, i.e. start to show the item 30 days before etc. The format for this would be:

date :: daysbefore :: Event

As an example:

2006-11-23 :: 30 :: Event Details 2006-12-14 14:23 :: 140 :: Other Event 2005-09-23 ::210 :: \<a href\=\"\"\>Go and look at Murk's Amazon Wishlist\</a\>

This is probably the most desired mod from my point of view.

The repeating event mod would change the format to include R for repeat

2006-11-23 :: 30 R :: Event Details 2006-12-14 14:23 :: 140 :: Other Event 2005-09-23 ::210 R :: \<a href\=\"\"\>Go and look at Murk's Amazon Wishlist\</a\>

Now, when an event is past the line would be deleted if there were no R present, and the year would be modified if there were. I imagine this would involve writing a new file line by line and then copying the new file over the old at the end. It would be up to the user to ensure there was a backup (it would not matter if it were outdated, as when pressed into use it would be modified!)


if [ -z "$1" ] ; then echo "I must have a filename to work with" exit 0 fi

# The Five Hours corrects the discrepancy between my server and me # MODIFY AS REQUIRED, My server is WEST of me uktime=$(date --date='5 hours' +%s) uktime2=$(date --date='5 hours' '+%B %d %H:%M')

sort $1 -o $1 echo "<ul class=\"module-list\">" # open file for reading exec 6<$1 # read until end of file while read -u 6 dta do event=$(echo $dta | sed "s@.*:: @@") whenisit=$(echo $dta | sed "s@::.*@@") optime=$(date --date="$whenisit" +%s) optime=$(($optime-$uktime)) if expr \( $optime \< 0 \) > /dev/null then optime=-$optime hours=$((optime/3600)) if [ $hours \< 24 ] then echo "<li>$event" echo " <span class=\"dateline\">(passed within last 24hrs)</span></li>" fi else year=$((optime/30000000)) # this will suppress any events more than a little less than a year off if expr \( $year \< 1 \) > /dev/null then echo -n "<li>$event <span class=\"dateline\">(" secs=$((optime%60)) mins=$((optime/60)) optime=$mins if expr \( $mins \< 60 \) > /dev/null then echo -n "$mins minutes and $secs seconds." else mins=$((optime%60)) hours=$((optime/60)) optime=$hours if expr \( $hours \< 24 \) > /dev/null then echo -n "$hours hour" if [ $hours != 1 ] then echo -n "s" fi #pluralisation echo -n ", $mins mins" else hours=$((optime%24)) days=$((optime/24)) optime=$days echo -n "$days day" if [ $days != 1 ] then echo -n "s" fi #pluralisation echo -n ", $hours hour" if [ $hours != 1 ] then echo -n "s" fi #pluralisation fi #hours fi #minutes echo ")</span></li>" fi #check that it isn't too far fi done

echo "<li class=\"lastupdate\">lastupdated: $uktime2 UK</li>" echo "</ul>"

# close file exec 6<&-

exit 0

SQL Backups

With thanks to Andy Budd's Page, I have finally worked out how to do decent backup/restores.

I created a text file called sqlbackup, in the file is this:


# echo start message echo "Backup Script Processing"

# navigate to backup dir if cd ~/backup.sql/latest then echo "...successfully navigated to backup dir" else echo "could not locate backup directory" exit 0 fi

# echo message echo "exporting SQL dump"

if #dump the db into a .sql file mysqldump --user=SQLUSERNAME --password=SQLPASSWORD.... .... SQLBLOGNAME --opt | gzip -c > backup-mt.sql.gz; then #echo success message echo "SQL dump successful" ls -la else #echo error message echo "mysqldump error" exit 0 fi

My crontab has:

# Backup MySQL 5 0 * * * /home/murk1e58/sqlbackup >> ~/error.log 2>&1 56 23 * * * cp ~/backup.sql/latest/backup-mt.sql.gz ~/backup.sql/daily/$(date +\%A).sql.gz 58 23 28 * * cp ~/backup.sql/latest/backup-mt.sql.gz ~/backup.sql/monthly/$(date +\%B).sql.gz

(The lines marked .... should be one one line, I have split them here to make sure the line is narrower than most screens). To restore the backup, one types:

gunzip backup.sql.gz mysql --user=username --password=password sqldatabasename < backup.sql

All good stuff!

Of course, what I really need is a completely seperate server, with similar features to this one (cpanel, command line etc), then I could sent the backup to it automatically and have it mirror this server!

In the short term, I would like to work out how to email the resulting file..... any ideas?