LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-06-2007, 09:47 PM   #1
anjanesh
Member
 
Registered: Sep 2004
Location: Navi Mumbai
Distribution: Ubuntu 14.04 64-bit
Posts: 230

Rep: Reputation: 30
Run script in a loop


Hi

I have this script that I want to run, say 100 times in a loop with a delay of 10 secs after each execution.

Is there

Code:
php script.php
sleep 10
How do I put this in a loop from 1 to 100 ?

Thanks
 
Old 03-06-2007, 09:53 PM   #2
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
are you wanting to put this in a bash script or a php script? A bash script would look something like this:

Code:
COUNTER=0
while [ COUNTER -lt 100 ]
php script.php
sleep 10
COUNTER=($COUNTER + 1)
done
 
Old 03-06-2007, 09:59 PM   #3
anjanesh
Member
 
Registered: Sep 2004
Location: Navi Mumbai
Distribution: Ubuntu 14.04 64-bit
Posts: 230

Original Poster
Rep: Reputation: 30
Bash/Shell script, not php.
I even tried using a loop but it doesnt seem to work.
Code:
[root@ip-xxx-xxx-xx-xxx test]# ./run.sh
./run.sh: line 6: syntax error near unexpected token `done'
./run.sh: line 6: `done'
[root@ip-xxx-xxx-xx-xxx test]#
 
Old 03-06-2007, 10:19 PM   #4
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
oops, my bad. that code should have been

Code:
COUNTER=0
while [ $COUNTER -lt 100 ]
do
php script.php
sleep 10
COUNTER=($COUNTER + 1)
done
That "do" keyword is rather important
 
Old 03-07-2007, 07:31 PM   #5
anjanesh
Member
 
Registered: Sep 2004
Location: Navi Mumbai
Distribution: Ubuntu 14.04 64-bit
Posts: 230

Original Poster
Rep: Reputation: 30
Do these shell scripts need a shebang line like #!/bin/bash ?
Isnt there anyway to get this working like the DOS batches files do ?
 
Old 03-07-2007, 10:16 PM   #6
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
the shebang line is required if the shell isn't /bin/sh, if it is /bin/sh you can get away with not putting it. You gotta remember to chmod +x it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
How to loop a script? rollo Linux - General 3 12-21-2006 05:39 AM
Loop ends unexpectedly after one run! trex_dk Programming 2 11-11-2005 03:49 AM
bash script loop bong.mau Programming 6 09-14-2005 07:38 PM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration