I'm on Ubuntu 18.04.6 LTS and I have a cronjob that schedules automatic shutdown commands to a specific
at
queue every minute:
$ crontab -e
*/1 * * * * [ -z "$(w -h)" ] && echo "/sbin/shutdown -h now" | at -q w "now + 1 hour"
I now have the problem, that when a machine is stopped by hand between now and +1 hour (meaning there is a job scheduled for execution), and the machine is rebooted the next day, it immediately shuts down again.
It seems that overdue at
jobs are executed when the system starts again. Of course this is very annoying, so I thought, I should delete those jobs when the machine starts again.
I created a script that removes all jobs from the queue in /usr/sbin/remove_shutdown_jobs
:
#!/bin/bash
jobs=$(atq -q w | cut -f1); if [ -n "$jobs" ]; then atrm $jobs; fi;
And I made it exectuable:
$ ls -lah /usr/sbin/remove_shutdown_jobs
-rwxr-xr-x 1 root root 81 Aug 22 12:06 /usr/sbin/remove_shutdown_jobs
I then tried to link it to the rc5.d
directory and gave it the name S00
so that it is executed **BEFORE** atd
is started (my guess is, that I have to remove the jobs before the at daemon is started, otherwise it could pick up those old jobs and execute them):
$ ln -s /usr/sbin/remove_shutdown_jobs /etc/rc5.d/S00remove_shutdown_jobs
$ ln -lah
lrwxrwxrwx 1 root root 30 Aug 31 13:49 S00remove_shutdown_jobs -> /usr/sbin/remove_shutdown_jobs
...
lrwxrwxrwx 1 root root 13 Jun 16 17:21 S01atd -> ../init.d/atd
...
But it seems, that the script is never executed. I tried it with a simple echo script that appends some text to file, and this is also not executed. I thought rc5.d
is the right directory, because of
$ runlevel
N 5
I also tried to link it into rc4.d
, rc3.d
and rc2.d
with no luck. I didn't link it to rc1.d
because this is only for some kind of rescue system and there where only K01
files in there (kill?), right?
Any idea what I'm missing, or what I've done wrong?
Asked by 23tux
(175 rep)
Sep 1, 2022, 12:31 PM
Last activity: Sep 12, 2022, 05:26 PM
Last activity: Sep 12, 2022, 05:26 PM