Sleep Timer Bash Script

Sleep Timer Bash Script

1 Comment on Sleep Timer Bash Script

Someone in Ubuntu Forums posted that they wanted to create a deb package full of useful scripts and was asking for help. In his post he also said that one of the scripts he was after was a sleep timer so I decided to post one in his thread for him.

The bash script uses zenity for the user interface and in Ubuntu and other Linux distributions needs to be executed with administrative privileges.

#!/bin/bash
echo "Sleep Timer."
TimeMinutes=$(zenity --entry --title "Sleep Timer" --text "How long before shutdown? (minutes)" --entry-text "30");
TimeSeconds=$(($TimeMinutes * 60))
if [ $TimeMinutes = 1 ]
  then
    echo "System power off in 1 minute. ($TimeSeconds seconds)"
  else
    echo "System power off in $TimeMinutes minutes. ($TimeSeconds seconds)"
fi
sleep $TimeSeconds
echo "powering off now..."
poweroff

About the author:

Bill Payne started working as a paid professional software developer at the young age of 12 years old developing simple games and other applications for pre-packaged computers. Bill has since developed software for many industries such as direct sales and the the stock market. Bill has now started sharing his many years of software development experience through a blog on the MPSHouse website and one on one lessons.

1 Comment

  1. Sleep Timer Bash Script | MPSHouse | Linux Blog  - 1 September , 2011 - 2:04 pm
    Reply /

    […] in Ubuntu and other Linux distributions needs to be executed with … Read the rest here: Sleep Timer Bash Script | MPSHouse This entry was posted in Uncategorized and tagged bash-script, his-post, his-thread, linux, […]

Leave a comment

Back to Top