Good day. Question to the adepts of Bash scripting. Can you please tell me which script can reboot the system every day at a certain time (for example, at 21:00)?

    2 answers 2

    Via cron:

    $ crontab -e -u root 21 0 * * * /sbin/shutdown -r now # запуск задачи в 0:21 
    • one
      Thanks all. I'll try in the beginning through the crowns. - Vasily

    So?

     while true; do HOUR=`date +%H` MINUTE=`date +%M` if [ $HOUR -eq "21" ] && [ $MINUTE -eq "00" ]; do echo $HOUR $MINUTE fi sleep 60s done 
    • 3
      The script may not work out sometimes. The fact is that sleep 60s will sleep at least 60 seconds. And maybe a little more. One second is easy. But since there is still code in the loop, it may happen that the first check will work at 20:59:59, and the second at 21:01:00. The simplest fix is ​​to change sleep for 30-40 seconds. But kroner is better. - KoVadim