1847156 Members
5948 Online
110263 Solutions
New Discussion

Re: Scripting help!

 
William Mounsey
Occasional Advisor

Scripting help!

I am having problems trying to figure out how to do this...

We currently have a script (scripta) that runs from 6am till midnight and never terminates within that time... Once it is run, it constantly outputs data to a log file to monitor transactions...

The problem is this script will periodically hang and then the transacations are not viewable via a custom app.

So I have written a script (scriptb) that monitors the date stamp on the log file and compares it to the actual time every 30 minutes. If the time difference is more than 30 minutes, my script (scriptb) runs the restart command for (scripta) And continues monitoring...

The problem is since scripta never terminates, my script just sits there... Of course, waiting to continue when scripta finishes...

Hope this doesn't sound too complicating... Here is the output of my script when it resets and when there is not problem if it helps...

DATE STAMP USER_QUERY
06:00 06:00
06:31 06:00
07:01 06:00
Wed Oct 1 07:01:09 CDT 2003
User Query log file is more than a half an hour old!
Time = 0701, User_Query = 0600
Time Difference = 101
Starting the kill_user_query script
Done!
Starting the start_user_query script

Here is the script results when there are no problems:

DATE STAMP USER_QUERY
06:00 06:00
06:31 06:00
07:01 06:00
07:31 07:31
08:00 08:00
08:31 08:31
09:00 09:00
09:31 09:31
10:00 10:00
10:31 10:31
11:00 11:00
11:31 11:31
12:00 12:00
12:31 12:31
13:00 13:00
13:31 13:31
14:00 14:00
14:31 14:31
15:00 15:00
15:31 15:31
16:00 16:00
16:31 16:31
17:00 17:00
17:31 17:31
18:00 18:00
18:31 18:31
19:00 19:00
19:31 19:31
20:00 20:00
21:31 21:31
22:00 22:00
22:31 22:31
23:00 23:00
23:31 23:31
8 REPLIES 8
James Randall
Frequent Advisor

Re: Scripting help!

My answer to this would be to have "scripta" dump its PID into a file.

"scriptb" could then do a "ps -p `cat `"....When that test come up empty...The script has finished...and "scriptb" can now quit.

James
No news is good news
James Specht
Trusted Contributor

Re: Scripting help!

I'd be interested in seeing scripta. It would be better to discover why it is hanging. Throwing programs at a program to fix the original program is dizzing!

--Jim
"Everyone can be taught to sculpt: Michelangelo would have had to be taught how not to. So it is with the great programmers."
William Mounsey
Occasional Advisor

Re: Scripting help!

I totally agree... Find out why it is hanging, but it turns out that we outsourced the writing of some software and this is one small portion... And my predecessors have spent many a waking hours trying to tie all the different variables together...

The final outcome was lets watch it and when it hangs, restart it...

And that is where I am at...
William Mounsey
Occasional Advisor

Re: Scripting help!

And I didn't quite understand the ps -p thing...
James Randall
Frequent Advisor

Re: Scripting help!

If you can get the process-id of the first script "scripta".....you can do the following in your loop.

PS_ID=`ps -ef | grep <scripta>`
.
.
.
MYTEST=`ps -p $PS_ID`
if [ "$MYTEST" = "" ]
then
exit
fi
.
.

James
No news is good news
James Randall
Frequent Advisor

Re: Scripting help!

Opps..

PS_ID=`ps -ef | grep <scripta> | awk '{print $1}'`

and then the rest from above.

James
No news is good news
James Randall
Frequent Advisor

Re: Scripting help!

O.K..

Its late in the day here.....And I'm losing it.

PS_ID=`ps -ef | grep <scripta> | awk '{print $2}'`
.
.
.
MYTEST=`ps -p $PS_ID`
if [ "$MYTEST" = "" ]
then
exit
fi
.
.

James
No news is good news
William Mounsey
Occasional Advisor

Re: Scripting help!

Ok... I understand now...

When the PID is null, then kick off the other script...

When scripta hangs, the PID is still valid and needs to be killed and the script is restarted...

The problem is when I restart the script (basically with a never ending loop), I can't continue my monitoring phase...
once it kicks off... Because it is waiting for a never ending loop type process to end before it continues...

I don't know if that clears things up or makes it more confusing...