This all depends on how you shutdown...do you:
1. use shutdown from gnome system menu?
2. use the shutdown command from a terminal?
If you are using shutdown from xterm, you can do something like the following example in your .bashrc:
Code:
shutdown() {
lsusb -d <vendor ID of your device> > /dev/null 2>&1
if [ $? = 0 ]; then
echo "USB Device found, please make sure you unplug your usb drive!"
else
echo "Shutting down system...do you want to:"
echo -e "\t1) shutdown"
echo -e "\t2) poweroff"
echo -e "\t3) reboot"
echo -n "Enter choice and press [enter]:"
read schoice
case "$schoice" in
1) /sbin/shutdown now;;
2) /sbin/poweroff;;
3) /sbin/reboot;;
*) echo "invalid choice, shutdown cancelled";;
esac
fi
}
If you use gnome shutdown, there isn't a way I know of to script the shutdown sequence, most customization you can do is post session.
You can however do this:
1. disable shutdown in gnome
https://www.redhat.com/archives/fedo.../msg01903.html
2. map hotkey to a shutdown script. Fire up gconf-editor (you may have to install it...run "yum gconf-editor" if its not installed), browse in /apps/metacity/global_keybindings, change the value of any run_command not used (e.g. run_command_1) and map for example, <shift>F1 to it.
3. map command to hotkey. Create a script called /root/bin/sd.sh, and in gconf-editor, goto /apps/metacity/keybinding_commands, and map say, command_1, to /root/bin/sd.sh.
Here's an example of what you could put into sd.sh:
Code:
#!/bin/bash
sclist="True shutdown False poweroff False reboot"
schoice=""
lsusb -d <vendorID> > /dev/null 2>&1
if [ "$?" = "0" ]; then
zenity --info --text "USB device found\!\n\nShutdown Aborted."
else
schoice=$(zenity --title "Shutdown Options" --text \
"Choose shutdown type, click cancel to abort." --list --radiolist \
--column "Selection" --column "Shutdown Type $sclist)
case "$schoice" in
"") zenity --info --text "Shutdown Aborted\!";;
shutdown) /sbin/shutdown now;;
*) /sbin/$schoice;;
esac
fi
So when you hit shift-f1 to shut down, this script will execute. This is just off the top of my head, I'm sure this could be optimized further, or someone knows of a better way to do this...hope this helps.