Skip to content

Instantly share code, notes, and snippets.

@JerryFleming
Last active April 18, 2018 03:00
Show Gist options
  • Save JerryFleming/5733304 to your computer and use it in GitHub Desktop.
Save JerryFleming/5733304 to your computer and use it in GitHub Desktop.
Shutdown your PC with graphical confirm dialog.
#!/bin/bash
# Shutdown the system, with GUI confirm box.
# by Jerry Fleming <jerryfleming2006@gmail.com>,
# on Jun 7, 2013,
# improved on Dec 20, 2013, for systemd compatibility.
# Use at your own risks!
TIME=3 # Three minutes count down.
PATH=$PATH:/sbin # For the shutdown command to be found.
TITLE='Shutdown Confirm'
# This will be interpolated twice, so be careful to quoting.
MSG="\#The system is scheduled to shutdown.\\\nDo you agree?\\\n\\\nYou have \$remain seconds left."
shutdown -h +$TIME &
let TIME*=60
who | awk '
{
# If it has a display, not tty or pts.
if($2 ~ ":"){print $1}
}
' | while read name
do
for step in $(seq $TIME)
do
remain=$(($TIME-$step))
eval echo "$MSG"
echo $(($step*100/$TIME))
sleep 1
done | sudo -u $name zenity --progress --title="$TITLE" --percentage=0 2>/dev/null \
|| shutdown -c "Shutdown cancelled by ${name}."
done
:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment