pastebin - collaborative debugging tool
kpaste.net RSS


Ouya countdown script
Posted by Anonymous on Sun 2nd Sep 2012 02:19
raw | new post

  1. #!/bin/bash
  2. # This script counts down the time to March 1, 2013. This is the month Ouya is supposed to be released to Kickstarter backers.
  3. # Press ^C to quit.
  4. # Date format yyyy-mm-dd
  5. #
  6.  
  7.  
  8. # $release and $now variables.
  9. # They represent the number of seconds since 1970-01-01 00:00:00 UTC,
  10. # for present time and release date respectively.
  11. now=$(date "+%s")
  12. release=$(date --date="2013-03-01" "+%s")
  13.  
  14. function tleft {
  15.  
  16.         # Check the current date/time and compare with release date.
  17.         now=$(date "+%s")
  18.         diff=$(( release - now ))
  19.  
  20.         # This for loop takes care of dividing the total number of seconds into days, hours, minutes and seconds.
  21.         for t in d h m s; do
  22.                 case $t in
  23.                         'd')
  24.                                 n=86400
  25.                                 d=$(( diff / n ))
  26.                                 printf 'days:\t%12ds\n' $(( d * n ))
  27.                         ;;
  28.                         'h')
  29.                                 n=3600
  30.                                 h=$(( diff / n ))
  31.                                 printf 'hrs:\t%12ds\n' $(( h * n ))
  32.                         ;;
  33.                         'm')
  34.                                 n=60
  35.                                 m=$(( diff / n ))
  36.                                 printf 'min:\t%12ds\n' $(( m * n ))
  37.                         ;;
  38.                         's')
  39.                                 s=$diff
  40.                                 printf 'sec:\t%12ds\n' $s
  41.                         ;;
  42.                 esac
  43.  
  44.                 # Sets the diff to the remainder after each run of the loop.
  45.                 diff=$(( diff % n ))
  46.         done
  47.  
  48.         # Prints out the time left.
  49.         printf '\n%s days, %02d:%02d:%02d left\n' $d $h $m $s
  50. }
  51.  
  52. # Quit if the current date is greater than the release date.
  53. if [[ $now -ge $release ]]; then
  54.         echo "OUYA! It's released any time now!"
  55.         exit
  56. else
  57.         # While the current date is less than the release date, check the time left once every 0.5 seconds.
  58.         while [[ $now -lt $release ]]; do
  59.                 clear
  60.                 tleft
  61.                 sleep 0.5
  62.         done
  63.  
  64.         echo "OUYA! It's released any time now!"
  65.         exit
  66. fi

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at