You are not logged in.

#1 2022-11-02 11:56:55

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,636
Website

using nohup in a script but unable to see status of backgrounded jobs

I have script that does some stuff but the key part is starting a series worker scripts it created like this:

#!/bin/bash

...

mapfile -t workers < <(find workers -name '*.sh' -printf "%f\n" | sort)
for i in "${workers[@]}"; do
  nohup workers/"$i" > "nohup.$i.log" &
done

Since the nohup was executed in the script, running jobs -l on the shell I used to run the script gives no results.  I am looking for some ideas to see the status of the worker scripts, are they running, finished, errored, etc?


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2022-11-02 13:01:21

dogknowsnx
Member
Registered: 2021-04-12
Posts: 652

Re: using nohup in a script but unable to see status of backgrounded jobs

Isn't the trailing '&' somehow defeating the purpose of 'nohup'?


RI - Rest your Eyes and Self

"We are eternal, all this pain is an illusion" - Maynard James Keenan

Offline

#3 2022-11-02 15:03:10

seth
Member
Registered: 2012-09-03
Posts: 57,195

Re: using nohup in a script but unable to see status of backgrounded jobs

https://unix.stackexchange.com/question … disown-and

Do you expect the master script to terminate before the jobs?
If not you could trap SIGUSR1 and make that print "jobs -l"
If yes, you could wait for all jobs before you terminate the script?
https://stackoverflow.com/questions/356 … xit-code-0

Online

Board footer

Powered by FluxBB