sequential running for 2 scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sequential running for 2 scripts
# 1  
Old 04-15-2009
sequential running for 2 scripts

Hello

I have a script that has 2 scripts that must be executed one after the other.
however, when I run the script, the 2 sub-scripts are run in parallel.

any idea how to fix this without using sleep command?

thank you
# 2  
Old 04-15-2009
use locks .... simple solution is use wait ......using pid of process
# 3  
Old 04-15-2009
Hammer & Screwdriver

Have script one create a file "script1running" when it starts, and delete it when done.

Embed some kind of wait or delay to make sure script one got a chance to create that locking file.
Then have script two in a loop checking for the existence if "script1running". Once the file does not exist, then script two can continue.
# 4  
Old 05-05-2009
Hi

Currently I am using this:

Fct1()
{
touch /tmp/lock$$
...
rm /tmp/lock$$
}
Fct2()
{
while [ -f /tmp/lock$$ ]
do
sleep 30
done
...
}


Is there a better way to synchronize? (I still need to test the above solution )

thank you.
# 5  
Old 05-05-2009
hi

can you please help in this?

thanks
# 6  
Old 05-20-2009
Quote:
Originally Posted by melanie_pfefer
Is there a better way to synchronize?
Checking the lock and creating the lock should be done as a single atomic operation, otherwise after the lock is not found and before it is created a concurrent process could also see no lock and decide to go on.

This is one way to do the check and the creation atomically:
Code:
until mkdir /tmp/lockdir 2>/dev/null; do
  sleep 1
done

The problem with mkdir is that if the script is aborted then a fictitous lock is left behind.
With trap you can provide a handler to remove the lock for any termination reason, but a SIGKILL cannot be trapped.

Last edited by colemar; 05-20-2009 at 07:19 AM..
# 7  
Old 05-20-2009
Quote:
Originally Posted by joeyg
Have script one create a file "script1running" when it starts, and delete it when done.

Embed some kind of wait or delay to make sure script one got a chance to create that locking file.
Then have script two in a loop checking for the existence if "script1running". Once the file does not exist, then script two can continue.
Hi Joyeg,

are you suggesting something like this-

Code:
#!/usr/bin/ksh
echo "this is a script that runs two script one after the other"
./dateformat.sh > script1running; wait 5 ; rm -f script1running;
for file in *;do
if [ $file = "script1running" ]
 then
   echo "the script1running file is there"
  else
   ./sample.sh
   break
  fi
   done

Thanks
NT

Last edited by namishtiwari; 05-20-2009 at 08:54 AM.. Reason: change the echo statement
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running scripts from a list

I am writing a bash script to run test some scripts. The names scripts of the scripts to tests are stored in an array. scptArr='chcksfrd.bash' scptArr='compute-misfit.bash' scptArr='compute-travel-times.bash' scptArr='create-data-tinv.bash' scptArr='create-docs.bash' ... (3 Replies)
Discussion started by: kristinu
3 Replies

2. Programming

Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX

Writing a Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX I have over the years come across the same issue a couple of times, and it normally is that the read speed on SAN is absolutely atrocious when doing non-sequential I/O to the disks. Problem being of... (7 Replies)
Discussion started by: vrghost
7 Replies

3. Shell Programming and Scripting

Shell Scripts (Renaming file names with sequential numbers)

Hi there, Firstly, I have no experience with shell scripts so would really appreciate some help. I have the following shell script that is causing some problems: moveit() { && set -x if then DOUBLE_DELIVERY=$(grep... (6 Replies)
Discussion started by: thebeno
6 Replies

4. Shell Programming and Scripting

sequential to line sequential

Hi I have a file sequential way i.e. written in contineous mode and the Record Seperator is AM from which the record is seperated .Now to process I have to make line sequential,and more over record length is not same it varies as per the input address, AM1234563 John Murray 24 Old streeet old... (5 Replies)
Discussion started by: vakharia Mahesh
5 Replies

5. Shell Programming and Scripting

Running 2 scripts one after the other using cron

I would like to run two scripts using cron one immediately after the other. Is it enough to put them one after another in the cron file to run at the same time, or will this cause them to run concurrently? (4 Replies)
Discussion started by: 3210
4 Replies

6. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/checkstatus.sh >> /u01/home/weblogic/logs/checkstatus.log The checkstatus.sh scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

7. Shell Programming and Scripting

Running scripts via su

Hi All, Am using the below command to start my application using the root user su - bin -c "/home/bin/test/start.sh" but am getting the error becaue i have set some environment varibales in bin .profile when i execute the command start.sh by logging directly into bin account it's... (8 Replies)
Discussion started by: ravi.sri24
8 Replies

8. Shell Programming and Scripting

Running three scripts parallelly

Hi All, We have three shell script batch, which extract data from three different systems(oracle, db2, db2/400). By running each shell script batch, the data is extracted from respective systems. while the batch is running, job date, system_name, start_date and end_date will be inserted into... (1 Reply)
Discussion started by: anwarsait
1 Replies

9. Programming

Reading special characters while converting sequential file to line sequential

We have to convert a sequential file to a 80 char line sequential file (HP UX platform).The sequential file contains special characters. which after conversion of the file to line sequential are getting coverted into "new line" or "tab" and file is getting distorted. Is there any way to read these... (2 Replies)
Discussion started by: Rajeshsu
2 Replies

10. Shell Programming and Scripting

running script sequential

I have 4 scripts I need to run sequentially(can't run simultaneously) What's the syntax for it? I am running Korn Shell. Thanks, (2 Replies)
Discussion started by: ocjunky
2 Replies
Login or Register to Ask a Question