Hi,
I am not a programmer but I needed to cobble together a script to save me time
manually downloading MP3's of a radio show that I like.
The functionality of the script is actually good so far however I am trying to remove
a puzzling error message. The script was originally in
KSH because I found an old
reference book on this shell. I then realised that I don't have this shell so I have
modified it to run in
BASH.
I have installed the Cygwin environment on a Windows PC.
Here is the script:Code:
#!/usr/bin/bash
exec 2>/dev/null #In KSh this sends ALL standard error for the script to dev/null but is this true for BASH?
function cleanup {
if [[ -a core ]]; then
rm core
fi
exit
}
trap cleanup INT TERM
while getopts ":f:u:" opt; do
case $opt in
f ) FOLDER="$OPTARG" ;;
u ) URL="$OPTARG" ;;
\? ) print >&2 "usage: rsi [-f LOCAL_FOLDER] [-u DOWNLOAD_URL]"
return 1
esac
done
shift $(($OPTIND - 1))
URL=${URL:-"http://www.slovakradio.sk/inetportal/rsi/core.php?lang=2"}
FOLDER=${FOLDER:-"C:/RSI"}
for i in $(lynx -source $URL | grep -o 'http://[^"]*.mp3' | uniq -i | sort -n | tail -6)
do
rsifile=$(basename $i)
if test -e $FOLDER/$rsifile
then
print "$rsifile was already downloaded."
else
print "Downloading $rsifile to $FOLDER."
wget -c --no-proxy --directory-prefix=$FOLDER $i
if test -s $FOLDER/$rsifile
then
print "Downloaded this file:"
fi
fi
done
exit 0
This is the output I get when the script finds existing files matching the
new MP3's
that I find from the webpage's source.
$ ./rsi -f Z:/RSI 2>/dev/null | tee logfile.txtQuote:
Can't find file ondemandRSI_relID2_soundID7338.mp3 was already downloaded.
Can't find file ondemandRSI_relID2_soundID7344.mp3 was already downloaded.
Can't find file ondemandRSI_relID2_soundID7349.mp3 was already downloaded.
Can't find file ondemandRSI_relID2_soundID7356.mp3 was already downloaded.
Can't find file ondemandRSI_relID2_soundID7362.mp3 was already downloaded.
Can't find file ondemandRSI_relID2_soundID7369.mp3 was already downloaded.
What is causing the "Can't find file " string in this error message? It's coming out of file descriptor 1 not 2
if that's significant at all since I am redirecting all standard error to dev/null.
Thanks, Nick.