Solved

how to run script multiple times

Posted on 2004-10-26
357 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
Question by:DMS-X
    8 Comments
     
    LVL 11

    Expert Comment

    by:avizit
    #!/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
    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
    GRRRR I thought for sure with bash it would be easier than this.
    0
     
    LVL 4

    Expert Comment

    by:nagraves
    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
    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
    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
    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:
    There's a program called 'anacron'. Very powerful and mature - allows you to run any command/script/program multiple times.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
    Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    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…

    933 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now