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