Shell script to run x times


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to run x times
# 1  
Old 03-10-2010
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,
# 2  
Old 03-10-2010
Code:
cd $SWDIR/util
cntr=1
while [ $cntr -lt 21 ]; do
./swadm add_process 1 BG Y
cntr=$(( cntr + 1 ))
done

# 3  
Old 03-10-2010
Quote:
Originally Posted by lookinginfo
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,
Script to run it N times. You get the idea for the 4/20 times scenario.

Code:
#!/bin/bash
TIMES=$1
cd "$SWDIR/util"
for((i=0; i < TIMES; i++)); do
  ./swadm add_process 1 BG Y
done

$ thescript.sh 20
# 4  
Old 03-10-2010
With user input:
Code:
#!/bin/bash
read -p "How many times ? " N
cd "$SWDIR/util"
for((i=0; i<N; i++)); do
  ./swadm add_process 1 BG Y
done

# 5  
Old 03-10-2010
Quote:
Originally Posted by lookinginfo
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

Code:
cd "$SWDIR/util" || exit 1  ## exit if cd fails
printf '%s ' "Number of times to run?"
read num
n=0
while [ $n -lt $num ]
do
  ./swadm add_process 1 BG Y
  n=$(( $n + 1 ))
done

# 6  
Old 03-12-2010
Thanks a lot folks.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. 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

3. Solaris

Set script to run during specific times

Hi all, I have this script which sends mail whenever the system is down. It works fine. Normally the system is down from 21 00 to 21 30 from Monday to Saturday and from 21 00 on Sunday to Monday 06 00 for maintenance. So I want the below script to run only when the system is up, i.e outside the... (2 Replies)
Discussion started by: frum
2 Replies

4. UNIX for Dummies Questions & Answers

script help shell session times out

while read s1 ; do url= suf=ignore=.csv; wget $url$s1$suf; sleep 5; cat /home/joey/public_html/charts/program/fn\charts/data/tickers/header.txt > $s1.txt; chmod 777 $s1.txt; sed '1d' table.csv?s\=$s1 >> /home/joey/public_html/charts/program/charts/data/tickers/$s1.txt; rm -Rf... (0 Replies)
Discussion started by: harte
0 Replies

5. 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

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

[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... (2 Replies)
Discussion started by: Dedalus
2 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. Shell Programming and Scripting

One shell script --2 parts need to execute during different times

Hi All, Have one job . first part of it needs to run on five days of the week , while second part of the job needs to run on two days of the week. How do I go abt this? Thanks (2 Replies)
Discussion started by: cbecentral
2 Replies
Login or Register to Ask a Question