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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find the shellscript which is running In background is completed or not?
# 1  
Old 05-17-2016
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
# 2  
Old 05-17-2016
Code:
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
This User Gave Thanks to andy391791 For This Post:
# 3  
Old 05-17-2016
Quote:
Originally Posted by andy391791
Code:
ps -ef | grep  abc.sh | grep -v grep

If there is an entry then the job is still running

If there isn't then the job has completed
This is more simply and more correctly done with:
Code:
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:
Code:
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.
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 05-17-2016
Moderator's Comments:
Mod Comment We are not here to help you cheat on homework nor to help you look qualified for a job you don't know how to do.

This thread is closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Running process in the background

Hi, I have this simple c program that creates duplicate process with fork(): #include <sys/types.h> main() { if (fork() == 0) while(1); else while(1); } I tried running it in the background gcc -o test first.c test & And I got this list of running process: (4 Replies)
Discussion started by: uniran
4 Replies

2. Shell Programming and Scripting

Running in background

Hello, I was trying to make some processes to run at background and went to a problem. First I tried just to loop in one line something like this: for i in {1..10}; do echo 'hello world' &; done; but it pops a syntax error, so I tried several ways to fix it but wasn't able to understand... (2 Replies)
Discussion started by: Rash
2 Replies

3. Shell Programming and Scripting

running the script in background

I have a script called startWebLogic.sh which I was running in the background but the problem is which I used the command :- ps -elf | grep "startWebLogic.sh" | grep -v grep to find the process id but I was unable to find the process id for this script and when I checked from the front end the... (3 Replies)
Discussion started by: maitree
3 Replies

4. Shell Programming and Scripting

run a shellscript in background after startup

hi. i need to start a shellscript AFTER full system startup the script will then run permanently in a loop checking the server every minute and in case of major hangs it just reboots the machine. i put it into /etc/rc.local file like this: #!/bin/sh -e # # rc.local # # This script is... (4 Replies)
Discussion started by: scarfake
4 Replies

5. UNIX for Advanced & Expert Users

Background job when completed

Hello - I submitted one background job last night and it completed today morning.I want to know exact time the job completed. I submitted backgroung job like this nohup cp -Rp /opt/apps/prod/proddb/proddata . & I want to know when above job completed on UNIX server.Above command... (9 Replies)
Discussion started by: Mansoor8810
9 Replies

6. Shell Programming and Scripting

Shellscript to find duplicates according to size

I have a folder which in turn has numerous sub folders all containing pdf files with same file named in different ways. So I need a script if it can be written to find and print the duplicate files (That is files with same size) along with the respective paths. So I assume here that same file... (5 Replies)
Discussion started by: deaddevil
5 Replies

7. UNIX for Dummies Questions & Answers

Running the Script in Background.

Gurus, Pls. help on this to run the script in background. I have a script to run the informatica workflows using PMCMD in script. Say the script name is test.sh & Parameters to the script is Y Y Y Y The no of parameters to the bove script is 4. all are going to be a flags. Each flag will... (2 Replies)
Discussion started by: prabhutkl
2 Replies

8. Shell Programming and Scripting

Running RSH on the background

Hi, I am developing a script that would do a 'rsh' on a client machine. I want to invoke a script in client machine which would keep on polling data to the server. I want the rsh to return back once it invoked the script on client and the script should run on background on client. ... (2 Replies)
Discussion started by: eamani_sun
2 Replies

9. Shell Programming and Scripting

running in background

i have a script called server.sh. how to run this script in backgroung using nohup command (5 Replies)
Discussion started by: ali560045
5 Replies

10. Shell Programming and Scripting

How to find the jobs running in background and stop

Hi All, I have requirement. I am running a job every 30mins. before starting the process, i need to check the process, if the process is still running then i need not trigger the process again, if it is not running then trigger the process again. I am using cron to trigger the shell script. Can... (7 Replies)
Discussion started by: srinivas_paluku
7 Replies
Login or Register to Ask a Question