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:
#!/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