Search code examples
linuxbashprocess

Start script after another one (already running) finishes


So I have a process running, and it will take several hours to complete. I would like to start another process right after that one finishes, automatically. Notice that I can't add a call to the second script in the first one, neither create another which sequentially runs both. Is there any way to do this in Linux?

Edit: One option is to poll every x minutes using pgrep and check if the process finished. If it did, start the other one. However, I don't like this solution.

PS: Both are bash scripts, if that helps.


Solution

  • Polling is probably the way to go, but it doesn't have to be horrible.

    pid=$(ps -opid= -C your_script_name)
    while [ -d /proc/$pid ] ; do
        sleep 1
    done && ./your_other_script