Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • Hey I truly appreciate this. But it does not seem to work in the crontab. Here is the grep of the syslog: Oct 30 00:22:02 hostname CRON[8298]: (user1) CMD ([ "$(</sys/class/thermal/thermal_zone0/temp)" -le 7000 ] || shutdown now) Oct 30 00:22:05 hostname CRON[8294]: (user1) MAIL (mailed 64 bytes of output but got status 0x0001 from MTA#012) Commented Oct 29, 2018 at 19:05
  • I tried this with sudo crontab -e also to launch it as root but doesn't work. Commented Oct 29, 2018 at 19:27
  • @ParthManiar See added bit at the end. Let me know what the email to root says if it fails. Commented Oct 29, 2018 at 19:59
  • Thank you very much. I did it with sudo poweroff in crontab of root and it worked. I do see an error after the first half of the command which is the output of temperature digits. I want to run multiple tasks: send an email before shutting down, stopping services and unmount drives before shutting down. Something like I am testing with 7000 as it is below the current temperature. [ "$(</sys/class/thermal/thermal_zone0/temp)" -le 7000 ] || /path_to_bash_script/1 >> /path_to_file/1.txt || cat /path_to_file/1.txt | mail -s "CRITICAL_SHUTDOWN_INITIATED" [email protected] || sudo poweroff Commented Oct 29, 2018 at 20:30
  • @ParthManiar I would suggest that you put everything in a script by itself and schedule that script with crontab. That would make it much easier. Scheduling things that are only one or two commands directly with crontab is ok, but as soon as you have three or more commands and some kind of conditional execution of things, then it's very much easier to just write that in a shell script and schedule that instead. This would make it easier to maintain the script without bothering about crontab. Also, if you run the cron job as root, you won't need sudo. Commented Oct 29, 2018 at 20:59