Last active
April 18, 2018 03:00
-
-
Save JerryFleming/5733304 to your computer and use it in GitHub Desktop.
Shutdown your PC with graphical confirm dialog.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Shutdown the system, with GUI confirm box. | |
# by Jerry Fleming <[email protected]>, | |
# 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