Skip to content

Instantly share code, notes, and snippets.

@BenHerbst
Created December 21, 2024 18:55
Show Gist options
  • Select an option

  • Save BenHerbst/ddb4e4e52803dde44e686e67926338a0 to your computer and use it in GitHub Desktop.

Select an option

Save BenHerbst/ddb4e4e52803dde44e686e67926338a0 to your computer and use it in GitHub Desktop.
This Shell Script turns off a laptop 10 seconds after the AC Power is lost
while true
do
if ! on_ac_power; then
notify-send "Lost Power. System shutdowns in 10 Seconds!"
echo "Lost AC-Power. Shutting down in 10 Seconds ..."
sleep 10
echo "You are on AC-Power"
echo "password" | sudo -kS shutdown -h now
fi
sleep 10
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment