Find if file available on Webpage
by orangepeel190 from LinuxQuestions.org on (#55V3D)
Hi There,
I am trying to find if a file is available on the particular website. Typically it is an .mp3.
If it is available, I wish to action a command, likewise if not available - either exit or action a command.
I have had a go, but not sure where I am going wrong... I am hoping to write this in BASH as the other files I am running are in bash - keeping it simple (if possible)...
Code:file=music.mp3"
url="http://www.some.site/here"
curl -s $url/$file | grep 404
if [ -f $file ] ; then
echo " File -> $file <- FOUND!"
Run_download_script_here
else
echo " File -> $file <- Not found!"
fi
exit 0Above is not displaying the desired result. I am simply wanting to check that the file is available on the website (for downloading).
I am getting lost with the grep section, possibly the If statement checking for the file showing on the website and whether or not I am required to download the file or is there a command to make sure that the file is there (rather than downloading it).
Hope that makes sense...?
Thank you very much
Cheers


I am trying to find if a file is available on the particular website. Typically it is an .mp3.
If it is available, I wish to action a command, likewise if not available - either exit or action a command.
I have had a go, but not sure where I am going wrong... I am hoping to write this in BASH as the other files I am running are in bash - keeping it simple (if possible)...
Code:file=music.mp3"
url="http://www.some.site/here"
curl -s $url/$file | grep 404
if [ -f $file ] ; then
echo " File -> $file <- FOUND!"
Run_download_script_here
else
echo " File -> $file <- Not found!"
fi
exit 0Above is not displaying the desired result. I am simply wanting to check that the file is available on the website (for downloading).
I am getting lost with the grep section, possibly the If statement checking for the file showing on the website and whether or not I am required to download the file or is there a command to make sure that the file is there (rather than downloading it).
Hope that makes sense...?
Thank you very much
Cheers