Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bash holding while command completes !

Status
Not open for further replies.

3wsparky

IS-IT--Management
May 25, 2003
121
GB
I am looking for some advice of what i should do to make my script run faster , it checks to see if a pcs conditions are meet if this is the case it executes a command , all works great apart from while its executing the command in this case a file copy it doesnt continue through my subnet until this copy is complete. im looking for a way to allow the copy to take place with out pausing the script ?

what do i need to do or what should i be looking at ?

many thanks
Terry
 
You can run a command in the background / asynchronously by adding an ampersand :

cmd &

For example :

cp bla.file /some/dir &

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
would this allow the script to continue running ?
I have a script that pings 255 addresses looking for responses and when i finds a response checks if the device is a pc or other if other then it should run a command if i added an '&' at the end would that allow the script to continue or is the use of the & to allow to commands to be run at the same time ?
 
As long as no user intervention is required, the & will allow it to continue even after the shell is closed. If this program does not end on its own, you'll have to kill it.

Mark
 
> I have a script that pings 255 addresses looking for responses
You need to be careful you don't create 255 concurrent copy commands then.

If average copy time is less than the average time it takes to find the next machine, there isn't much to worry about. One copy will usually finish before the next one starts.

But if copying takes longer, you will accumulate more and more background copy commands, which might lead to a rather unresponsive machine.

Of course, you have to be mindful of the situation changing over time, like adding more machines to the network, or copying more files.

--
 
not too long ago, I helped a friend to write a script to fire up multiple povray tasks to parallelize his rendering on a openmosix cluster. I can't find that script of mine now but from the top of my head:

Code:
#!/bin/bash
counter=1
iterations=254
threads=3

while(( $counter <= $iterations ))
do

while (( $(ps -fC cp | grep -i "[i][cp process to match][/i]" | wc -l) < $threads ))
do
        cp [i][b]source destination[/b][/i] &
        counter=`expr $counter + 1`
done

sleep 3s
done

Perhaps you could modify this script to suite your needs.

--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
zeland,
Just for snicks, what kinds of boundaries would you put on "optimizing" the number of running, concurrent threads?

Memory required per thread?
# of physical CPUs?
Other criteria?

I'm just curious since your example used "3"?
(after all the Universal Answer is "42", right?....)

Thanks for the OT post, don't mean to hijaak the thread)

D.E.R. Management - IT Project Management Consulting
 
I used 3 because that was the number of openmosix nodes my friend had. It would be pointless to have more than 3 povray processes running back then. In this case of file copying however, if 5 threads finish just as fast as 3 threads but not as fast as 6, then I would suppose 5 should be your limit. You could also lower your sleep count to 1s to poll for finished processes faster if the amount to be copied to each machine is small.

--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top