# Linux newbie scripting help needed (timer)

**URL:** <https://community.unix.com/t/linux-newbie-scripting-help-needed-timer/301538>\
**Category:** Shell Programming and Scripting\
**Created:** [December 22, 2011, 1:39am UTC](https://community.unix.com/t/linux-newbie-scripting-help-needed-timer/301538 "2011-12-22T01:39:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pop45398](https://community.unix.com/letter_avatar/pop45398/32/6_22734026db12803ebb3e059622ac3534.png) [@Pop45398](https://community.unix.com/u/Pop45398)\
**Post date:** [December 22, 2011, 1:39am UTC](https://community.unix.com/t/linux-newbie-scripting-help-needed-timer/301538/1 "2011-12-22T01:39:44Z")

</div>

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:

```nohighlight
#!/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 

```

---

<div class="post-metadata">

**Author:** ![Pop45398](https://community.unix.com/letter_avatar/pop45398/32/6_22734026db12803ebb3e059622ac3534.png) [@Pop45398](https://community.unix.com/u/Pop45398)\
**Post date:** [January 3, 2012, 12:38am UTC](https://community.unix.com/t/linux-newbie-scripting-help-needed-timer/301538/2 "2012-01-03T00:38:11Z")

</div>

Managed to figure how the Dialog timer option works. Thanks for all the help.
