[bash] Run a program many times

Tags
bash, run automatically, shell scripts

 
Thread Tools Search this Thread
# 1  
Old 08-17-2009
[bash] Run a program many times

Hi

I'm running a program many times with differents input.
I mean that i run my_prog with some parameters and i wait till the end, then i start again another simulations with some others differents parameters.

Is possible to make it automatic with a script bash.
Maybe i need some function to check if the program has completed its task.

thanks

D.

Sorry for the post. I've already found a solution.
We can use the pidof function. It works like:

if [ (pidof process_name) ] then

echo "It's already running"

else

echo "Not running"

Last edited by Dedalus; 08-17-2009 at 12:12 PM.. Reason: solution found
# 2  
Old 08-17-2009
is like you say xD
Code:
if pidof $1 
then
    echo "Is runnig"
else
    echo "Is NOT runnig"
fi

# 3  
Old 08-17-2009
Re; [bash] Run a program many times

Any reason why you wouldn't use "wait" ?

I'm assuming from what you say the program is running in the background, hence the issue with regards to knowing what it's finished .. how about something like;

Code:
for i in `cat parameters`
do
    echo "Testing with $i"
    time ./my_prog $i
    wait $!
done

Depending on your parameters you'll probably need something a little more complete than "cat parameters", but in principle this will wait for my_prog to finish even if it backgrounds ..

Or .. for a batch in parallel ..

Code:
list=""
function me()
{
    ./my_prog $1
    list="$list $!"
}

for i in `cat parameters`
do
    echo "Testing with $i"
    time me $i
done

wait $list

'Course if they all finish around the same time, the output from "time" might be interesting to interpret ... Smilie

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
How to run several bash commands put in bash command line? abdulbadii Shell Programming and Scripting 4 01-23-2018 07:11 AM
Run a job between times else run later twinion Shell Programming and Scripting 4 03-01-2015 07:13 PM
Set script to run during specific times frum Solaris 2 08-06-2014 09:10 PM
Running a program multiple times to search pattern and assign structure bioinfo Shell Programming and Scripting 3 01-29-2013 12:03 PM
shell program- how many times a function is called oana06 UNIX for Dummies Questions & Answers 0 03-27-2012 06:25 PM
Compare times to run a program - Serial vs MPI rpd25 Programming 1 01-30-2012 06:49 PM
Run .command at specific times JustChillin1414 Shell Programming and Scripting 2 03-07-2011 11:39 PM
Run Program from Bash CGI-Script JMooney5115 Homework & Coursework Questions 8 01-27-2011 07:51 PM
Counting script how many times it run? utoptas Shell Programming and Scripting 3 08-06-2010 03:22 AM
Shell script to run x times lookinginfo Shell Programming and Scripting 5 03-12-2010 12:24 PM
Need to run same script multiple times in parallel rahman_riyaz Shell Programming and Scripting 2 08-15-2009 11:19 PM
how to know the application run on which core, and run how many times on this core yanglei_fage Programming 2 06-28-2009 04:47 AM
Checking mem usage at specific times in a program pl4u UNIX for Advanced & Expert Users 2 04-05-2009 06:26 PM
how to make your bash script run on a machine with csh and bash npatwardhan Shell Programming and Scripting 3 11-19-2008 04:17 AM
Can I use $1 several times in shell program? whatisthis Shell Programming and Scripting 3 09-14-2004 05:22 PM