How to monitor a shell script called within a script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to monitor a shell script called within a script?
# 1  
Old 08-22-2013
How to monitor a shell script called within a script?

HIi Guys... I am in a fix.... 1st the code :

Script 123.sh looks like this :

Code:
./abc # a script which is getting called in this script
while true
do
     count=`ps -ef | grep abc | wc -l`
     if [ $count -gt 1]
     echo "abc is running
     sleep 10
     fi
done

but the process is getting checked only after ./abc is getting finished.... Smilie

is there any command or a way in which I can parallely check the abc process within 123.sh?

Please help me out!!!!

Last edited by Scott; 08-22-2013 at 11:40 AM.. Reason: Please use code tags
# 2  
Old 08-22-2013
Maybe you want to run "abc" in the background:

Code:
./abc &

# 3  
Old 08-22-2013
Hi Scott

So if I try running it in background shall it work?..Can you provide me the script?
# 4  
Old 08-22-2013
Code:
./abc &
while :; do
  jobs %1 2> /dev/null >&2 || break
  echo "abc is running..."
  sleep 5
done


Last edited by Scott; 08-22-2013 at 12:22 PM.. Reason: changed to use jobs instead of ps
This User Gave Thanks to Scott For This Post:
# 5  
Old 08-23-2013
Hi Scott...Thanks a lot for ur help..but you know I am in a fix again Smilie

Code:
nohup ./processProv.sh &
while true
do
count=`ps -ef | grep processProv | wc -l`
if [ $count -gt 1 ]
            echo "Process is running (Process Prov)
            er=`grep -i Error processProv.log | wc -l` #a log where I need to  check   error generated or not parallely along with this#
                   if [ $er -ge 2 ]
                       echo "Error found " 
                       exit 1
                   fi
fi
sleep 5
done

.....but it is getting stuck after the main process (nohup ./processProv.sh &) is getting complete(maybe because of sleep 5 command)...can you please suggest an alternate code so that the : process running + error check is also validated as long as the main script runs?...processProv.log is the log which gets creates once ./processProv.sh starts...

Last edited by Scott; 08-23-2013 at 11:41 AM.. Reason: Please use code tags
# 6  
Old 08-23-2013
You never leave the loop unless you find an error. Either use the break command as Scott demonstrated or use a different loop.
Code:
#!/bin/bash
nohup ./processProv.sh &
PID=$!
while ps -p $PID >/dev/null 2>&1; do
   echo "Process is running (Process Prov)
   er=`grep -i Error processProv.log | wc -l` #a log where I need to check error generated or not parallely along with this#
   if [ $er -ge 2 ]
      echo "Error found "
      exit 1
   fi
   sleep 5
done

Edit: Scotts check is more robust - on very busy systems you may find another process than the background process if process numbers warped.

Last edited by cero; 08-23-2013 at 11:35 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pass values to a script called from within another script in shell?

Ceiling Light - The Forgotten Element One of the highest details concerning using an LED ceiling panel essentially offer a fantastic dance floor which definitely makes the customers dance right away.They are a quite low cost method of something like a lighting solution, simple collection up,... (1 Reply)
Discussion started by: harveyclayton
1 Replies

2. UNIX for Beginners Questions & Answers

How to pass values to a script called from within another script in shell?

Need ideas on how to achieve the below. We have a script say "profile.sh" which internally calls another existing script called "name.sh" which prompts for the name and age of a person upon execution. When i run profile.sh how can i populate a pre-defined value from another file and pass that... (1 Reply)
Discussion started by: sankasu
1 Replies

3. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

4. Shell Programming and Scripting

Python script called by a shell script

experts, i wrote a python script to do a certain job, i tried it and it is working fine, i want this script to be executed automatically after a ksh script, the problem is when i execute the ksh script my python script runes perfectly after the ksh script as I have include it at the end of the ksh... (1 Reply)
Discussion started by: q8devilish
1 Replies

5. UNIX for Dummies Questions & Answers

Interpreting Shell Script errors when called from CRON

Hi All, I am calling a series of shell scripts via CRON so everything is running as root. However, in my error log file I am seeing the following errors. Please can anyone offer any advise as to the possible causes and solution to prevent the errors from appearing. The Error 1227 seems to... (2 Replies)
Discussion started by: daveu7
2 Replies

6. UNIX for Dummies Questions & Answers

How to retrieve the value of variable in shell script which is called by crontab

There are two files one is shell script (sample.sh) and another is configuration file (sampl_conf.cfg) configuration file contains one variable $FTP_HOME. the value of this variable vaires for user to user. If user is say jadoo then value is /home/jadoo/ftp/, for user1 - /home/user1/ftp. The... (4 Replies)
Discussion started by: jadoo_c2
4 Replies

7. Shell Programming and Scripting

environment variable in shell script called through crontab

Please help me on below.. https://www.unix.com/shell-programming-scripting/141533-retrieve-value-environment-variable-shell-script-called-crontab.html#post302442024 I'm still here. I can still see you! (0 Replies)
Discussion started by: jadoo_c2
0 Replies

8. Shell Programming and Scripting

How to return the value from the called shell script to the calling sh script

Hi all, I have two ksh scripts #sample1.sh #!/bin/ksh . ./sample2.sh echo $fileExist #sample2.sh #!/bin/ksh func() { i=1 return $a } func echo $? Here how should I return the value of sample2.sh back to sample1.sh? Thanks in advance. (2 Replies)
Discussion started by: gp_singh
2 Replies

9. Shell Programming and Scripting

gzip in shell script called by cron

I'm puzzled by this one. I hope you can explain it to me. I have a ksh shell script that gzips a file among other things. This works perfectly fine when the script is manually run through a shell. However, when the same script is run through cron, it does everything correctly, but it will... (2 Replies)
Discussion started by: hbau419
2 Replies
Login or Register to Ask a Question