Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to run script multiple times

Posted on 2004-10-26
8
Medium Priority
?
359 Views
Last Modified: 2012-05-05
I have a script that needs to either loop 100 times from start to finish or needs to be exicuted 100 times. This script is getting run through cron at a specific time. For now I have pointed my cron job to another script that has 100 lines calling up the script I need to run. This is not practical at all. Basically somthing like this would be nice
#100x ./script-name.sh
Or some kind of variable in the script itself that loops from start to finish 100 times.

Thanks,
DMS
0
Comment
Question by:DMS-X
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 11

Expert Comment

by:avizit
ID: 12411871
#!/bin/bash
 COUNTER=0
 while [  $COUNTER -lt 100 ]; do
             /path/to/your/script            
             let COUNTER=COUNTER+1
 done
0
 
LVL 11

Expert Comment

by:avizit
ID: 12412052
BASH Programming - Introduction HOW-TO
7. Loops for, while and until

http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html
0
 
LVL 1

Author Comment

by:DMS-X
ID: 12412205
GRRRR I thought for sure with bash it would be easier than this.
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 4

Expert Comment

by:nagraves
ID: 12416325
avizit's method works fine..

put their script in say: ~/counter.sh
chmod +x counter.sh

make your crontab call ~/counter.sh

This will run your other script 100 times when crontab kicks in and runs counter.sh.
0
 
LVL 4

Expert Comment

by:nagraves
ID: 12416338
Or alternately, you can remove the          /path/to/your/script          and put your entire script in the middle of the looping structure.
0
 
LVL 4

Expert Comment

by:bytta
ID: 12416663
It can't get much easier than this.
The "cleanest" version (the one with the least characters) is:

 #!/bin/bash
for i in $(seq 100)
             /path/to/your/script            
done

but it all works the same...
0
 
LVL 8

Expert Comment

by:da99rmd
ID: 12421130
You can make it more general by adding this:
#!/bin/bash
# ./runTimes <nrOf> <app>
for i in $(seq $1)
do
             $2            
done

/R
0
 
LVL 1

Accepted Solution

by:
goldwarlock earned 2000 total points
ID: 12447506
There's a program called 'anacron'. Very powerful and mature - allows you to run any command/script/program multiple times.
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question