How do I programmatically terminate a script from another script?

0
4
Asked By CuriousCoder42 On

Hey there! I'm trying to figure out how to kill a running script that I start during system boot in order to run a different one later with cron. The script in question is located at ~/scripts/default.sh. I'm familiar with commands like ps and pkill, but I'm not sure of the exact steps or commands to accurately terminate this first script. Any advice would be really appreciated!

2 Answers

Answered By ScriptingWizard99 On

You can use the command `pkill -f "default.sh"` to easily kill your running script. A good tip is to give your scripts unique names to avoid confusion, especially if you have multiple scripts with similar names.

Answered By ShellGuru88 On

If you're using cron, one way to handle this is to have cron execute a wrapper script. This script can start your default script in the background, save its PID to a file, and later use that file to kill the script. You can run a script in the background by appending `&` to the command and then capturing the PID with `$!`.

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.