Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 360
user3070433 Avatar asked May 14 '26 22:05

user3070433


2 Answers

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???).

like image 153
user3689515 Avatar answered May 17 '26 11:05

user3689515


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.

like image 43
Alexander L. Belikoff Avatar answered May 17 '26 12:05

Alexander L. Belikoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!