user3070433
user3070433

Reputation: 31

Unix Shell Script: sleep command not working

i have a scenario in which i need to download files through curl command and want my script to pause for some time before downloading the second one. I used sleep command like sleep 3m but it is not working. any idea ???

thanks in advance.

Upvotes: 3

Views: 14646

Answers (3)

user3689515
user3689515

Reputation: 41

Make sure your text editor is not putting a /r /n and only a /n for every new line. This is typical if you are writing the script on windows.

Use notepad++ (windows) and go to edit|EOL convention|UNIX then save it. If you are stuck with it on the computer, i have read from here [talk.maemo.org/showthread.php?t=67836] that you can use [tr -d "\r" < oldname.sh > newname.sh] to remove the problem. if you want to see if it has the problem use [od -c yourscript.sh] and /r will occur before any /n.

Other problems I have seen it cause is cd /dir/dir and you get [cd: 1: can't cd to /dir/dir] or copy scriptfile.sh newfilename the resulting file will be called newfilenameX where X is an invisible character (ensure you can delete it before trying it), if the file is on a network share, a windows machine can see the character. Ensure it is not the last line for a successful test.

Until i figured it out (i knew i had to ask google for something that may manifest in various ways) i thought that there was an issue with this linux version i was using (sleep not working in a script???).

Upvotes: 4

Alexander L. Belikoff
Alexander L. Belikoff

Reputation: 5711

Are you sure you are using sleep the right way? Based on your description, you should be invoking it as:

sleep 180

Is this the way you are doing it?

You might also want to consider wget command as it has an explicit --wait flag, so you might avoid having the loop in the first place.

Upvotes: 3

Olivier Dulac
Olivier Dulac

Reputation: 3791

while read -r urlname
do
    curl ..........${urlname}....
    sleep 180  #180 seconds is 3 minutes
done  <   file_with_several_url_to_be_fetched

?

Upvotes: 0

Related Questions