How to check the status of script for every 5 min? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

How to check the status of script for every 5 min?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-15-2013
gnnsprapa gnnsprapa is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 31 January 2014, 4:26 AM EST
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
How to check the status of script for every 5 min?

Hi,

Can any1 provide the code for my req:
I am loading few set of files into database through one unix script. I ll try to describe the process:

load_cdr-->main script
Source Feeds are A & B.
File in A-akm.dat
File in B-bkm.dat
Now my script runs through cron jobs everyday...and for both A&B it runs parllely...i.e script will start loading data from akm also and bkm also...prob is these two files try to update same table at some point and gives an error.

for eg: i use one script named as daily.sh which consist of commands which start my script

Code:
nohup opt/app/dev/scripts/load_cdr.sh A > opt/app/dev/logs &
nohup opt/app/dev/scripts/load_cdr.sh B > opt/app/dev/logs &

I cannot go with an option where i run my script sequentially for each source Feeds. So need smthing like sleep command usage ..

**when ever any feed's file start loading it creates some lock file..
eg: if akm.dat dile of source feed A is getting loaded in temp dir A.lck file gets created and similarly for B feed also..

Now i want that my script should check if A.lck file exist in that folder and if it is present and B feed try to load then script loading B feed should go into sleep mode and check in every 5 min if A.lck file got removed or not..once it got removed B file starts loading

It might be bit confusing ..so please let me knw if i missed ny pt.

TIA
Sponsored Links
    #2  
Old 10-15-2013
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 26 June 2014, 10:29 AM EDT
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
Have a look at this and that.

If you want to make sure your script are launched sequentially you may give a try to something like :

Code:
opt/app/dev/scripts/load_cdr.sh A > opt/app/dev/logs &
pid=$!
wait $pid
opt/app/dev/scripts/load_cdr.sh B > opt/app/dev/logs &


Last edited by ctsgnb; 10-15-2013 at 04:11 AM..
Sponsored Links
    #3  
Old 10-15-2013
gnnsprapa gnnsprapa is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 31 January 2014, 4:26 AM EST
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
thnx ctsgnb..

can you plz tell me what does pid=$!.

well i also came up with this idea but can u tell me how to check for the lock file existence and if exists then execute sleep command..something like

if [-f a.lck] then
check if opt/app/dev/scripts/load_cdr.sh B > opt/app/dev/logs is active and if both cond true then
suspend the opt/app/dev/scripts/load_cdr.sh B > opt/app/dev/logs till lck file gets removed..my guess is we have to provide some while loop with sleep command...
    #4  
Old 10-15-2013
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 26 June 2014, 10:29 AM EDT
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
$!is the pid of the last background process
wait $pidwill wait until $pid is finished

Code:
$ sleep 60 &
[1] 8092
$ echo $!
8092
$ ps -ef | grep [s]leep
oracle 8092  3817  0 11:00 pts/1    00:00:00 sleep 60
$


Code:
$ date +%T ; sleep 60 &
11:06:15
[1] 8100
$ wait $! && date +%T
[1]+  Fini                    sleep 60
11:07:15
$


Last edited by ctsgnb; 10-15-2013 at 05:07 AM..
Sponsored Links
    #5  
Old 10-15-2013
sea sea is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 27 July 2014, 7:56 PM EDT
Location: Swissh
Posts: 319
Thanks: 38
Thanked 38 Times in 38 Posts
As it is the file same called, but with a diffrent argument, it depends if also the first argument should be forced to 'sleep' until the lockfile is gone...

In that case it could look simliar:

Code:
#!/bin/sh
LOCKFILE=/opt/app/dev/load_cdr.lock
FIXSTR="-bkm.dat"

[[ -z $1 ]] && echo "No args supplied";exit 1;
while [[ -f $LOCKFILE ]];do sleep 5M;done

case "$1" in
"A")	touch $LOCKFILE
	echo "Parsing $1$FIXSTR"
	sleep 30
	rm $LOCKFILE
	;;
"B")	echo "Parsing $1$FIXSTR"
	rm $LOCKFILE
	;;
esac

Hope this helps
Sponsored Links
    #6  
Old 10-15-2013
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 26 June 2014, 10:29 AM EDT
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
Your flag may unexpectedly remains in case your script is killed while running in the critical section.

To avoid this you should set a trap.

I suggest you read the following article which gives clues about some common implementation weakness while scripting (check especially the sections relating to flag/lock files)
Sponsored Links
    #7  
Old 10-22-2013
heman96 heman96 is offline
Registered User
 
Join Date: Oct 2013
Last Activity: 9 November 2013, 1:48 AM EST
Location: USA
Posts: 21
Thanks: 8
Thanked 0 Times in 0 Posts
Trap

Hi Guys ...

Need help

HTML Code:
$ cat trap.sh
#!/bin/bash
trap cleanup 1 2 3 15
cleanup()
{
echo “I was running \”$BASH_COMMAND\” when you interrupted me.”
echo “Quitting.”
exit 1
}
while :
do
echo -en “hello. “
sleep 1
echo -en “my “
sleep 1
echo -en “name “
sleep 1
echo -en “is “
sleep 1
echo “$0”
done
Can anyone guess why "1 2 3 15" is need as argument to cleanup function ?

Thanks
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help....script check status if see something then send email dotran Shell Programming and Scripting 6 10-18-2013 04:53 PM
SFTP script - poll every min to check file complete before transfering srineel UNIX for Dummies Questions & Answers 4 08-09-2009 01:53 PM
check exit status - Expect Script iamcool Shell Programming and Scripting 1 01-02-2008 08:07 AM
Script to check status of a PID zeekblack Shell Programming and Scripting 14 10-03-2006 03:09 PM
how to check exit status in awk script epall UNIX for Dummies Questions & Answers 1 06-24-2006 07:27 PM



All times are GMT -4. The time now is 05:15 PM.