Visit Our UNIX and Linux User Community


[bash] Run a program many times


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [bash] Run a program many times
# 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

Previous Thread | Next Thread
Test Your Knowledge in Computers #10
Difficulty: Easy
Charles Babbage was a British mathematician and inventor, known as the 'Father of the Computer'. He designed a mechanical computer called the Analytical Engine which was an early forerunner of the modern computer.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run a job between times else run later

Hi guys, I have written a script that waits for a trigger file. Then checks the time of the trigger. if the trigger finished between 8pm and midnight then runs a job. else it waits till 1am then runs a different job. I am still very new to scripting so any suggestions to improve my... (4 Replies)
Discussion started by: twinion
4 Replies

2. UNIX for Dummies Questions & Answers

shell program- how many times a function is called

We have a program source C and is required to indicate how many times each function is called from the C program. also print the line number where there is a call. I've tried something like this: #!/bin/sh for i in $*;do if ! then echo $i is not a C file. else echo $i... (0 Replies)
Discussion started by: oana06
0 Replies

3. Programming

Compare times to run a program - Serial vs MPI

Hi, I have a fortran program with serial and MPI version. I want to compare the time taken by these programs to run. I use ifort/gfortran compiler. How to compare the time taken by each program to run? Is there any sample code for comparison? Thanks, rpd (1 Reply)
Discussion started by: rpd25
1 Replies

4. Shell Programming and Scripting

Run .command at specific times

Okay so I've got a command to start my java server up, but I want it to start at say 8:00AM and then stop at 11:00PM. In order to stop it I have to type stop and press enter in the terminal. I've been trying to get this to work and I'm having no luck. Here's my command: #!/bin/bash cd "`dirname... (2 Replies)
Discussion started by: JustChillin1414
2 Replies

5. Homework & Coursework Questions

Run Program from Bash CGI-Script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: This is a problem I am having with my 2 semester senior project. I have a LAMP server running Ubuntu 9.10 with... (8 Replies)
Discussion started by: JMooney5115
8 Replies

6. Shell Programming and Scripting

Counting script how many times it run?

i should use this script runs how many times before ? how can i do_? (3 Replies)
Discussion started by: utoptas
3 Replies

7. Shell Programming and Scripting

Shell script to run x times

Hi, First i need to cd to this directory $SWDIR/util Second i need to run the following either 4 times or 20 times ./swadm add_process 1 BG Y how can i put this in a script which should ask for user input on how many times you want to run this Thanks, (5 Replies)
Discussion started by: lookinginfo
5 Replies

8. Shell Programming and Scripting

Need to run same script multiple times in parallel

Hi all, I have a requirement in which a script invokes a Java program. Lets say script ABC invokes a java program with cfg file a parameter. This script takes 10 minutes to execute . Like this ineed to run the program 10 times meaning 100 minutes if i do it sequentially. If i open... (2 Replies)
Discussion started by: rahman_riyaz
2 Replies

9. UNIX for Advanced & Expert Users

Checking mem usage at specific times in a program

Hi all, I'm running a simulator and I'm noticing an slow increase in memory for long simulations such that the simulation has to end because of a lack of memory. A colleague of mine ran Valgrind memcheck and reported that nothing of interest was reported other than known mem leaks. My advisor... (2 Replies)
Discussion started by: pl4u
2 Replies

10. Shell Programming and Scripting

Can I use $1 several times in shell program?

Hi, I am new to Unix and shell programming. I am trying to write a shell program to read 4 variables from command line. For example, Please enter your name: somebody Please enter your address: address plase enter your phone: phone I'd like to save all threee variables in my program for... (3 Replies)
Discussion started by: whatisthis
3 Replies

Featured Tech Videos