How can I programmatically stop a running script from another script?

0
5
Asked By CuriousCoder42 On

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.

2 Answers

Answered By ShellNinja89 On

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.

Answered By ScriptSavvy007 On

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.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.