Advertisement
miamondo

poweroff.sh

Dec 15th, 2021 (edited)
1,119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.49 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Copyright © 2021 Benoît Boudaud https://miamondo.org/contact
  4. #This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
  5. # License as published by the Free Software Foundation, either version 3 of the License, or any later version.
  6.  
  7. #This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  8. # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  9. # You should have received a copy of the GNU General Public License along with this program.
  10. # If not, see <http://www.gnu.org/licenses/>
  11.  
  12. # ----------------------------------------------------------------------------------------------------------------------
  13.  
  14. poweroff=$(date -d "00:00" +%s) # Correspond à l'heure d'extinction
  15. time_before_poweroff=$[$poweroff - $(date +%s)] # Calcul du temps restant avant extinction.
  16.  
  17. if [ $time_before_poweroff -lt 0 ] # Si le temps restant est négatif, cela signifie que l'extinction est passée.
  18. then # Alors, on rajoute un jour (86400 secondes) et on recalcule.
  19.     time_before_poweroff=$[($poweroff+86400) - $(date +%s)]
  20. fi
  21.  
  22. sleep $time_before_poweroff # Le script se met en pause jusqu'à l'extinction.
  23.  
  24. # Puis, à l'heure convenue, il lance la commande rtcwake.
  25.  
  26. rtcwake -l -m off -s 25200
  27.  
  28. # ----------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement