After looking at that link…
Looks like a whole learning process.
My current knowledge level isn’t ready to proceed into the custom systemd service level.
This is something in my future, but it seems a little too advanced for me currently.
Instead of the first five fields, one of eight special strings may appear:
string meaning
------ -------
@reboot Run once, at startup.
@yearly Run once a year, "0 0 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "0 0 1 * *".
@weekly Run once a week, "0 0 * * 0".
@daily Run once a day, "0 0 * * *".
@midnight (same as @daily)
@hourly Run once an hour, "0 * * * *".
Please note that startup, as far as @reboot is concerned, is the time when the cron(8) daemon startup. In particular, it may be before
some system daemons, or other facilities, were startup. This is due to the boot order sequence of the machine.
Well, no. That’s wrong, too. You’re both actually correct…but imprecise this one time.
Cron does indeed have the @reboot feature.
However, the OP has specified they want some jobs to run at shutdown before the reboot occurs. cron @reboot is not capable of that.
@WyattWhiteEagle you are asking cron to do something that it’s not designed to do. Doing jobs at shutdown is tricky, because they mustn’t be critical – maybe you lose power or have some other “unclean” shutdown. A missed job shouldn’t lead to failed boot or lost data. And if they are not critical, why can’t they be done at startup instead?
Your choice is to alter your requirement (do job at startup instead of shutdown), OR to use a different tool that is capable of doing the job (like systemd). It doesn’t matter to us which you choose.
If you want more detailed advice, you might need to share a bit more about what you want to accomplish.
I wasn’t answering op’s question about shutdown jobs. Merely pointing out a minor incorrectness in that cron can and has for many years been able to do something after on reboot, that’s all.
Thank you for that.
Indeed it does seem a bit easier to follow and understand.
More like it’s complimentary or a summarized version of the first link I was provided with.
I’ve used this past couple days to give this topic some thought to try and get my thoughts straight about it.
Seems @ian-weisser is correct about me giving more details about what I want to accomplish.
The part about running cronjobs at intervals, I can understand why that was mentioned.
Running a cronjob at shut down isn’t a good idea, just as @ian-weisser pointed out.
I’m guessing that’s where the systemd service comes in, especially when the shut down is concerned.
I’m spending most of the time trying to maintain my machine.
So one of my goals is to open time for what I got the machine for…
Goal: To do more in family and homestead upkeep.
There is some constructive hobby entertainment as well.
(I use the machine to help keep my thoughts and routines at least somewhat consistent)
What I want to accomplish…
When I first get to the machine in my mornings, I always manually reboot, first thing.
This reboot isn’t consistent as to when I do the reboot.
The machine is running the rest of the time unless something happens that requires me to reboot more than once.
Sometime before shut down…
Send logs, crash reports if any, and at least the most recent system snapshot to somewhere off the machine.
Within an hour before shut down…
Cleanup the system.
After the bootup…
Run updates and upgrades
This will allow me to spend 2-4 hours instead of 8 to 10 hours every day rectifying errors.
Those hours include testing to verify the errors have been rectified.
The current cronjob does all this at 4:03am every day except the system snapshot.
I just need to find out how to include the most recent snapshot and how to seperate what all is done on which side of the reboot.
I wasn’t doubting the manpages,
I was making sure I understood it properly.
I misunderstood before and had ill results.
Thus, my need for a VM setup. (got another thread goin’ for that.)
(right now, I’m working on someone else’s comp)