I want to run a shell script upon system shutdown in Knoppix Live (which runs from a writable USB flash drive) so that I can backup some data and ftp it to a remote server. The script works fine but I'm not sure where to put it so that it executes when the system goes into shutdown.
You could add your script to
My concern with this approach is if your script takes a long time to execute. eg FTP site is slow or not available. I'm not sure if the shutdown process will wait for your script to finish, or if your backup script will be killed because it is taking too long. I'll leave that as an experiment for you! :-)
You could write a little wrapper script to shutdown your system. Something along the lines of …
which you could then execute using
You could save the file as backup.sh in your home directory within the area being backed up.
Call the script from the .bash_logout file in your home directory. So when the machine goes down, you get logged out, the script runs.