Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell adding a sleep and loop

Tags:

shell

how would I make this pause for 10mins then start back up and continuously loop...

#!/bin/sh

for page in {1..50}
do
        wget -q -U Mozilla "http://www.domain.com/cat_search/item.html?p=$page" -O - \
         | tr '"' '\n' | grep "^Item photo for " | cut -d ' ' -f 4 >> bpitem.txt
        sleep 15
done
like image 578
acctman Avatar asked Aug 10 '11 15:08

acctman


People also ask

How do you sleep 10 seconds in shell script?

/bin/sleep is Linux or Unix command to delay for a specified amount of time. You can suspend the calling shell script for a specified time. For example, pause for 10 seconds or stop execution for 2 mintues. In other words, the sleep command pauses the execution on the next shell command for a given time.

How do I put sleep in a bash script?

How to Use the Bash Sleep Command. Sleep is a very versatile command with a very simple syntax. It is as easy as typing sleep N . This will pause your script for N seconds, with N being either a positive integer or a floating point number.

How do I create a delay in sh file?

Within the script you can add the following in between the actions you would like the pause. This will pause the routine for 5 seconds. read -p "Pause Time 5 seconds" -t 5 read -p "Continuing in 5 Seconds...." -t 5 echo "Continuing ...."

How do you make an infinite loop in shell?

The following syntax is used for create infinite while loop in a shell script. echo "Press [CTRL+C] to exit this loop..." You can also Unix true command with while loop to run it endlessly.


2 Answers

Enclose the code in a while like this:

while :
do
    your_code
    sleep 600
done
like image 82
jman Avatar answered Jan 03 '23 10:01

jman


Put it in an infinite loop like this:

while :
do
   for page in {1..50}
   do
        wget -q -U Mozilla "http://www.domain.com/cat_search/item.html?p=$page" -O - \
         | tr '"' '\n' | grep "^Item photo for " | cut -d ' ' -f 4 >> bpitem.txt
        sleep 15
   done
   sleep 10m
done
like image 41
dogbane Avatar answered Jan 03 '23 10:01

dogbane