Linux newbie scripting help needed (timer)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Linux newbie scripting help needed (timer)
# 1  
Old 12-22-2011
Linux newbie scripting help needed (timer)

Hi,

Newbie to Linux needing some help with scripting, here. I've written a script that allows easily shutting down, rebooting, or exiting to terminal mode via a Dialog menu after logging out of X-server. In my .bash_profile I have startx followed by running my script, shutdownmenu.sh, and it works as I wanted but now I'd like to automatically shut down the computer in 5 seconds unless reboot or terminal mode is selected before the timeout. Is it possible to add a timer to my script to perform this? TIA. Here's my script:
Code:
#!/bin/bash
# shutdownmenu.sh - A shell script for a shutdown menu

# Store menu options selected
INPUT=/tmp/menu.sh.$$

# Clear screen then display menu box
dialog --clear \
--title "[ Shutdown Options ]" \
--menu "Use the UP/DOWN arrow keys, the first letter of the choice, \
or the number keys 1-3 to choose an option." 12 50 3 \
Shutdown_computer "" \
Restart_computer "" \
Terminal_mode "" \
2>"${INPUT}"
 
menuitem=$(<"${INPUT}")
  
# make decsion 
case $menuitem in

# delete temp file then shutdown
  Shutdown_computer) [ -f $INPUT ] && rm $INPUT; poweroff;;

# delete temp file then reboot
  Restart_computer) [ -f $INPUT ] && rm $INPUT; reboot;;

# delete temp file then exit to terminal
  Terminal_mode) [ -f $INPUT ] && rm $INPUT; clear;;

# catchall for cancel or other input
# delete temp file then exit to terminal
  *) [ -f $INPUT ] && rm $INPUT; clear;;
esac

# 2  
Old 01-03-2012
Managed to figure how the Dialog timer option works. Thanks for all the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Timer application in linux

Hello everyone, It is good to be here. I am a newbie to Linux.Can anyone help me in designing a timer application. The timer has to start.And after certain time interval the program should call a function continuously.It should not be in sleep mode.During the course of that time interval the... (0 Replies)
Discussion started by: Harry443
0 Replies

2. Shell Programming and Scripting

Newbie help needed for comparing values

Being linux administrator my task is to keep the machines up and running .Everyday i get a report of list of machines that are up and running. it would be nice if i get list of machines that are shutdown in comparison to yesterdays report. for example.If there are 5 machines in my environment... (5 Replies)
Discussion started by: pinga123
5 Replies

3. Shell Programming and Scripting

Scripting needed for newbie

Hi, I am newbie in shell scripting I have a file name like simple.txt which comes from Mainframe systems onto windows dir every 15 minutes daily. File name is same. Every 15 minutes it updates. I need to write shell script to check if the file arrived every 15 min or not. If the new file... (4 Replies)
Discussion started by: chinniforu2003
4 Replies

4. Shell Programming and Scripting

scripting newbie... some help please?

hi all, i am just getting in to bash scripting, so don't be too harsh... i've created this little backup script, and it's just awfull... ugly, doesn't work like I want it to, the works. anyways, i was hoping some of you might help me improve it and learn a little in the process. what i... (13 Replies)
Discussion started by: jmd9qs
13 Replies

5. Shell Programming and Scripting

Hi Needed help for Unix Newbie

Hi, Can i get some help from any of you guyz on writing Unix script. my requirement is like reading a csv file, finding a specific pattern in the lines and repalce the string with new string and write it to another file. My file is file ABC123.dat Col1,Col2,Col3 102628,AB10 0,21... (2 Replies)
Discussion started by: prashant_jsw
2 Replies

6. Shell Programming and Scripting

scripting newbie needs help

I have written a script that will email a generic user when a device is "offline". I would like to enhance this by having the script lookup a contact's email and automatically add it to the MAIL_LIST. I am trying to lookup and return data based on a field common in two files File 1 ... (0 Replies)
Discussion started by: irishluck66
0 Replies

7. Shell Programming and Scripting

Scripting Newbie

Seems simple but I am having difficulty with this one: I am trying to write a single command line argument (which will be a path) - the program should print out the owner of the path. I can not get anything I write to run. Please help. (5 Replies)
Discussion started by: Kymmers7
5 Replies

8. HP-UX

urgent help needed on HP 9000 rp3410 server for a newbie

Hi friends i dont know whether it is the right forum to ask this or not. if its not please excuse me and please give me the link for such a forum. i am novice about HP 9000 rp3410 server and its things but i had to install and configure it. I came to know that it doesnot comes with builtin... (4 Replies)
Discussion started by: bnaravinda
4 Replies

9. UNIX Desktop Questions & Answers

Newbie help needed connecting to Internet

I have an Ultra5 with 2.56 that is connected to a network. We don't use a proxy server on the network but access the internet directly through a gateway. How do I configure the Solaris box to see the internet? Opening the internet explorer and setting HTTP; FTP etc ports to the ip of the... (3 Replies)
Discussion started by: FattyLumpkin
3 Replies
Login or Register to Ask a Question