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

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

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 :

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 & 

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...

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:

#!/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

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)

Hi Guys ...

Need help

$ 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