Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two scripts running at the same time thru cronjob. Will it affect?

Status
Not open for further replies.

prog3

Programmer
Jun 3, 2003
9
US
Hi,

I have 2 scripts running at the same time through cronjob. The scripts have the same functionality except for the path names, creating log files.

The scripts are as follows.
Script A:
#!/bin/sh
RPT_TO=/home/scripta
RPT_LOG=/home/loga
V=`ps -eaf | grep AB | wc -l`
if [ $V -gt 1 ]; then
echo "Process AB is running. Exiting the script." >> $RPT_LOG/delete_a.log
exit
fi
.
.
some more processing
end of script A.

Scrpit B:
#!/bin/sh
RPT_TO=/home/scriptb
RPT_LOG=/home/logb
V=`ps -eaf | grep AB | wc -l`
if [ $V -gt 1 ]; then
echo "process AB is running. Exiting the script." >> $RPT_LOG/delete_b.log
exit
fi
.
.
some more processing
end of script B.

The cron job is set as follows.
00 19 * * 1-5 /home/loca/a.sh >> /home/loca/a.log 2>&1
00 19 * * 1-5 /home/loca/b.sh >> /home/loca/b.log 2>&1

The time when the scripts ran, AB process was not running
Scipt B ran through fine. Script A, gave the message "process AB is running. Exiting the script."
Is this because both the scripts running at the same time, doing the same process checks and using the same variable name?
What could be the reason script a is giving the message even though the process AB is not running?

Any suggestions is appreciated.

Thanks in advance.
 
> Scipt B ran through fine. Script A, gave the message "process AB is running. Exiting the script."
What script A found was not the AB program, but the 'grep AB' process in script B which was started at about the same time (it too contains the text "AB" in the process description).

Short answer is, you need a more sensitive way of determining whether a process is running
 
Thanks for the information, Salem.
How do I resolve this problem?

Can I start running the scripts at different times?
What other ways do I have to find if the process AB is running?
 
In your grep lines, add this:

V=`ps -eaf | grep AB | grep -v grep | wc -l`

The grep -v eliminates your grep command looking for AB.
 
Just FYI,
You can eliminate the grep -v grep like this...

ps -eaf | grep [A]B | wc -l

Just put the first character of the text string in []'s.

just a tad more efficient.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top