Sleep: Difference between revisions

Jump to navigation Jump to search
355 bytes added ,  6 June 2023
Line 177: Line 177:


=== BASH example: download file and sleep random seconds between 1 ~ 7 seconds ===
=== BASH example: download file and sleep random seconds between 1 ~ 7 seconds ===
The following script checks if a specific file exists in a defined path. If the file doesn't exist, it downloads the file from a provided URL and then pauses for a random duration between 1 and 7 seconds. If the file already exists, it simply prints a message stating that the file was found and the download was skipped.


<pre>
<pre>
Line 188: Line 190:
</pre>
</pre>


Same command
The same command can be written on one line:
<pre>
<pre>
if [ ! -f /path/to/paper.pdf ]; then curl "https://website/to/pdf" -L -o /path/to/paper.pdf; sleep $((1 + RANDOM % 7)); else echo "File found. Download skipped."; fi
if [ ! -f /path/to/paper.pdf ]; then curl "https://website/to/pdf" -L -o /path/to/paper.pdf; sleep $((1 + RANDOM % 7)); else echo "File found. Download skipped."; fi
Anonymous user

Navigation menu