Countdown timer shell script

I made a small countdown script for the shell. It goes as follows:

#!/bin/bash
# USAGE
# ./countdown <num of seconds> <msg>
# eg:
# ./countdown 300 Time to rock!
date1=$((`date +%s` + $1));
shift
while [ "$date1" -ne `date +%s` ]; do
echo -ne "$(date --date @$(($date1 - `date +%s` - 19800 )) +%H:%M:%S)\r";
done
notify-send 'Timer finished' "$*"
zenity --info --title "Timer finished" --text "$*"
view raw countdown hosted with ❤ by GitHub

Some tricks used in the script include:

  1. echo -ne "blah blah \r" was used to write in the same line over and over
  2. That 19800 is the time difference from GMT 0.0 in seconds. In Sri Lanka, it’s 5.30 hrs. Yes, we’re dealing with epoch time here, but still trying to figure out why we need to offset the time difference. 😕
  3. notify-send sends a desktop notification
  4. zenity --info pops up a message box

You can also add a sound to play with mplayer.

Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Your email address will not be published. Required fields are marked *