Last active
          September 13, 2016 15:48 
        
      - 
      
- 
        Save flxai/8f03077dd74d836b4474733721512c50 to your computer and use it in GitHub Desktop. 
    flipdot Shutdown on disconnected power supply
  
        
  
    
      This file contains hidden or 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 | |
| # When the power supply is disconnected, shut down machine after a defined time | |
| # and warning messages | |
| # Time in seconds to shutdown device after disconnected power supply | |
| grace_time=500 | |
| timeout=0 | |
| while :; do | |
| state=$(upower -i "$battery" | grep state | awk '{print $2}') | |
| if [[ $(cat /sys/class/power_supply/AC/online) -lt 1 ]]; then | |
| time_left=$((grace_time-timer*60)) | |
| notify-send -u critical "Power supply disconnected" "System will shutdown in $((time_left/60)) minutes" | |
| if [[ "$time_left" -le 0 ]]; then | |
| notify-send -u critical "SHUTTING DOWN SYSTEM" | |
| systemctl poweroff | |
| exit 0 | |
| fi | |
| ((timer++)) | |
| else | |
| timer=0 | |
| fi | |
| sleep 60 | |
| done | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment