Countdown bash script:
#!/bin/bash
if [ "$#" -lt "2" ] ; then
echo "Incorrect usage ! Example:"
echo './countdown.sh -d "Jun 10 2011 16:06"'
echo 'or'
echo './countdown.sh -m 90'
exit 1
fi
now=`date +%s`
if [ "$1" = "-d" ] ; then
until=`date -d "$2" +%s`
sec_rem=`expr $until - $now`
echo "-d"
if [ $sec_rem -lt 1 ]; then
echo "$2 is already history !"
fi
fi
if [ "$1" = "-m" ] ; then
until=`expr 60 \* $2`
until=`expr $until + $now`
sec_rem=`expr $until - $now`
echo "-m"
if [ $sec_rem -lt 1 ]; then
echo "$2 is already history !"
fi
fi
while [ $sec_rem -gt 0 ]; do
clear
date
let sec_rem=$sec_rem-1
interval=$sec_rem
seconds=`expr $interval % 60`
interval=`expr $interval - $seconds`
minutes=`expr $interval % 3600 / 60`
interval=`expr $interval - $minutes`
hours=`expr $interval % 86400 / 3600`
interval=`expr $interval - $hours`
days=`expr $interval % 604800 / 86400`
interval=`expr $interval - $hours`
weeks=`expr $interval / 604800`
echo "----------------------------"
echo "Seconds: " $seconds
echo "Minutes: " $minutes
echo "Hours: " $hours
echo "Days: " $days
echo "Weeks: " $weeks
sleep 1
done
salviamo il file come bash-countdown.sh:
$ chmod +x bash-countdown.sh
adesso siamo pronti per il conto alla rovescia:
countdown per le ferie:
$ ./bash-countdown.sh -d "AUG 07 2010"
sab 12 giu 2010, 16.49.59, CEST
—————————-
Seconds: 0
Minutes: 10
Hours: 7
Days: 6
Weeks: 7
countdown di 90 minuti:
$ ./bash-countdown.sh -m 90
countdown per Inghilterra-Stati Uniti stasera:
$ ./bash-countdown.sh -d 20:30:00
Questo lo script, per chi ha bisogno di un applet, esiste timer-applet.