Linux from the command line - Scheduling tasks for later with 'at'
Yesterday I posted about cron and crontab and using them to schedule tasks to run regularly. But what if you want to run a task once at a later time?
That's where 'at' comes in.
https://linuxconfig.org/how-to-schedule-tasks-using-at-command-on-linux
Speaking of scheduling tasks, hopefully you know how to use the 'shutdown' command to shutdown or reboot your Linux box properly from the command line right? But did you know it could do other tricks, including scheduled shutdowns or reboots?
ReplyDeleteshutdown
Shutdown and reboot the system.
- Power off (halt) immediately:
shutdown -h now
- Reboot immediately:
shutdown -r now
- Reboot in 5 minutes:
shutdown -r +5 &
- Shutdown at 1:00 pm (Uses 24h clock):
shutdown -h 13:00
- Cancel a pending shutdown/reboot operation:
shutdown -c
Funny story. I once ran "shutdown -h 5" on a sysv machine so that I could add a SCSI device. It shut down in 5 seconds. The coworker who was running Emacs on that box was very unhappy with me.
ReplyDeleteAdrian Colley Yeah, back when there were a dozen UNIX flavours, BSD, and Linux, these kinds of little inconsistencies could drive you nuts.
ReplyDeleteChristopher Gaul that's why I have a script called pc-shutdown, along with it being able to shout at me if it is the build server instead of my machine, hehe.
ReplyDeleteFunny story, sort of:
Shutdown's manual page flagged some option as stop fucking using that around 95 or 96 I think. My employer's legacy code base had been using that flag up until a few years ago.
Porting that legacy software to a newer OS, I only had to make about two changes for systemd. Replace the sysvinit script which hadn't really been touched since the early days of Fedora Core, and change the software's reset command. Depending on the options given it will trigger a hardware watchdog or use the shutdown command to reboot the system.
Sure enough the systemd version of shutdown didn't implement this option and that code path was failing accordingly. I've been spread across enough flavors of Unix and Linux that this was no surprise, obscure arguments to shutdown are never very reliable.
I brought up the FreeBSD manual pages website and looked through the man pages for Red Hat and SuSE systems, and stopped looking when about twenty years of man pages ago, I found that mysterious switch flagged as "Stop fucking using that, assholes". And then updated the branch accordingly.