Pausing and resuming a Bash script
The only way to do it AFAIK:
- Store any variables or other script context information in a temporary file to set the script state just before pause. It goes without saying that the script should include a mechanism to check that file to see if the previous execution is suspended and, if so, get the entire context and resume accordingly.
- After rebooting, manually run the script again, OR the script will automatically run from your script run profile.
source to share
Intriguing ...
You can pause in BASH with CTRL-Z, but after reboot, you won't be able to resume. A reboot initializes the machine and the process that was suspended is terminated.
However, it may be possible to force the process to start in coredump using "kill -QUIT $ pid and then use
gdb" to restart the script. I tried for a while but was unable to do so. Perhaps someone else can provide the path.
source to share
If this applies to your script and the job it is executing, add breakpoints to it - this means that all process state will be saved to disk before continuing. Then ask each individual part to check if there is an output they should produce and skip if there is. This should make rerunning the script almost as efficient as resuming from the same place during execution.
Alternatively, run the script in a virtual machine. Freeze the virtual machine before shutting down the real system and resume after. It probably costs a really huge and complex shell script for this.
source to share