(I've searched for answers for this, but all seem to be for older versions of Ubuntu.)
Is there a similar crontab trigger such as "@reboot" for shutdown scripts, and if not, why not?
(I've searched for answers for this, but all seem to be for older versions of Ubuntu.)
Is there a similar crontab trigger such as "@reboot" for shutdown scripts, and if not, why not?
No, because @reboot is
Run once, at startup.
but running a script at shutdown that way makes no sense because your system is going down and the system would 'kill' your script.
When you shutdown your system, it will first send the SIGTERM and wait some time before killing any program, so you can react to that. Here is how.
I don't understand why you would want to run a script from cron when the system is shutting down, perhaps I am missing something. Instead of running a script at shutdown, why not just run a script which does what you need it to do before calling the shutdown command. For example, call the script preshutdown.sh:
Run command 1 and output results to a log file.
Run command 2 and append results to the log file ....etc
Shutdown when finished with sudo shutdown -h now
When you next power up the system you can view the log to see the results of the commands which ran in the script.
Edit: To answer the OP's question exactly, there is no crontab trigger for shutdown. If you want to run scripts when pressing the "Shutdown" button in the GUI, or by running the shutdown command in a terminal, put them in /etc/rc6.d, where they will be executed in alphabetical order. Their names must start with K99 and they must be executable.