How to find the shellscript which is running In background is completed or not?

HI All,

I need the answer of below question?

1) how to find the shellscript which is running In background is completed or not ?

ex: I know the shellscript name abc.sh which is running in background through cronjob. I want to know this is job is still running or stopped, how to check this ?

Regards,
Priyanka

ps -ef | grep  abc.sh | grep -v grep

If there is an entry then the job is still running

If there isnt then the job has completed

1 Like

This is more simply and more correctly done with:

ps -ef | grep -q 'abc[.]sh'

which will give you a zero exit status if one or more copies of processes are running with a name containing the string abc.sh . Using [.] instead of just . gets rid of the need for grep -v grep and keeps strings like abcdsh from accidentally being selected.

If there might be other processes running that are named with a longer string containing abc.sh , you can avoid that problem with the more complex:

ps -ef | grep -Eq '( |/)abc[.]sh( |$)'

Note that none of these suggestions will keep this from mistakenly indicating that abc.sh is running if any process is running with an argument that is abc.sh .

1 Like
Moderator comments were removed during original forum migration.