Repeat function in shell script

Hi all,

I want to use the wget command to download a file from a webpage and if just in case the file is empty the script should repeat the wget command.

something like this

wget -q -O - http://www.someurl.something > /tmp/file
if [[ -s /tmp/file ]] ; then
echo "$FILE has data." (Continue rest of the script)
else
echo "$FILE is empty." (Repeat the wget command until file contains data then continue rest of the script)
fi ;

Thanks for any help.

You can do something like that :

>/tmp/file
until [ -s /tmp/file ]
do
   wget -q -O - http://www.someurl.something > /tmp/file
done

Jean-Pierre.

Hi Jean-Pierre,

Thanks for the reply, your advice works but is in a loop and doesn't stop.
Any ideas?

It loops because the file does't contain any data, that's what you wanted.
It would be better to insert a
sleep 10 (or any other number of seconds) to avoid overloading (and possible banning of your IP) of the server. It would be better to put a maximum iterations (20 in the example below) in the loop for the same reason.

>/tmp/file
until [ -s /tmp/file ] || [ $I -gt 20 ]
do
     wget -q -O /tmp/file www.someurl/something
     let I+=1
     sleep 10
done