Testing a process has ended (in the background)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Testing a process has ended (in the background)
# 1  
Old 11-11-2010
Testing a process has ended (in the background)

Hi guys. Hopefully this question will make sense!

Continuing on my script to automatically copy some huge files across the network onto various servers as background jobs, I need to be able to check that each job has finished successfully.

The script below shows what I want - almost. The problem is that some processes may obviously finish sooner than others, even though they were started afterwards. But the way the script is written it will do the first one, and when that's completed check the second one (which may already be done).

What I need is a way of getting the wait and exit code parts to also run as background jobs so they will finish as soon as the process has - but I'll be darned if I can work out how that would be written. I'm sure it'll be simple, but my brain is fried!

Anyone got any ideas? Thanks in advance. Smilie


Code:
set -A processvar
countervar=1
while [[ $countervar -le 4 ]]
do
   seconds=$(( (RANDOM%60+1) ))
   echo $seconds
   sleep $seconds &
   processvar[$countervar]=$!
   (( countervar=countervar+1 ))
done

countervar=1
while [[ $countervar -le 4 ]]
do
   wait ${processvar[$countervar]} ; echo Exitstate = $?
   (( countervar=countervar+1 ))
done

# 2  
Old 11-11-2010
are you using rsync to copy the large files? or scp? or something else?
# 3  
Old 11-11-2010
Hi, I'm using SCP to do the copy. Sorry, I should have mentioned but I am using "sleep" in the example script just to show the situation. In the real one sleep will be replaced with an scp to copy the files.

Last edited by dlam; 11-11-2010 at 06:20 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make background process interact with fg process

Hi, I have written a menu driven shell script in which as per the choice, I run the another script on background. For eg: 1. get info 2)process info 3)modify info All the operations have different scripts which i schedule in background using &. However I wish to display the error... (0 Replies)
Discussion started by: ashima jain
0 Replies

2. Shell Programming and Scripting

How to put FTP process as a background process/job in perl?

Hi, I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming. So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Discussion started by: vanitham
5 Replies

3. Shell Programming and Scripting

Finding process which ended another process

Hello, The scenario is as follows, I have a background process running initially for which i know the PID on machine1. I use ssh from machine 2 to execute a script in machine 1. For some reason the back ground process is terminated. I would like to know which process caused the... (6 Replies)
Discussion started by: prasbala
6 Replies

4. UNIX for Dummies Questions & Answers

Process which ended another process

Hello, The scenario is as follows, I have a background process running initially for which i know the PID on machine1. I use ssh from machine 2 to execute a script in machine 1. For some reason the back ground process is terminated. I would like to know which process caused the ... (1 Reply)
Discussion started by: prasbala
1 Replies

5. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

6. Shell Programming and Scripting

Background Process.

How to create a backgrond processes ? (5 Replies)
Discussion started by: anupdas
5 Replies

7. Solaris

background process

Hi When I run ./script.sh & the script runs in bg But when I close the telnet session, the script is killed also. any idea how to keep this script running? thx (4 Replies)
Discussion started by: melanie_pfefer
4 Replies

8. Shell Programming and Scripting

background process

can anybody plz tell me how can i find the background processes running. (2 Replies)
Discussion started by: Raom
2 Replies

9. Shell Programming and Scripting

background process

Hello, This has probably been answered in other forms, however I would like to confirm this statement before I use it in production. Will this syntax work for a background process? echo "nohup server_process1 >/dir1/nohup.server_process1 2>&1 &" | ksh Please advise. Thanks (1 Reply)
Discussion started by: jerardfjay
1 Replies

10. Shell Programming and Scripting

capture the process id when starting a background process

Hello all, How do I start a background process and save the process id to a file on my system. For example %wait 5 & will execute and print the process id. I can't figure out how to get it to a file. I've tried: > filename 0>filename 1>filename. Any assistance is most appreciated. Thanks, Jim... (10 Replies)
Discussion started by: jleavitt
10 Replies
Login or Register to Ask a Question