How can I programmatically stop a running script from another script?
Asked by
fresco.restorer
I'm trying to figure out how to kill a script that automatically starts at boot so that I can replace it with another script later using cron. Specifically, I'm working with a script located at ~/scripts/default.sh, and I'm looking for a reliable method to terminate it programmatically. I've heard of commands like ps and pkill, but I'm not sure about the exact steps or commands to use for this.
Answers
You can use the command `pkill -f "default.sh"` to terminate it. It's a straightforward way to stop the script, especially if you uniquely label the script to avoid confusion with others that may have the same name.
Reply to this answer
If you're using cron, you could set it up to run a script that starts your main script in the background and saves its PID to a file. Then, later, you can refer to that file to kill the specific script using the recorded PID.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions