I'm downloading files from a remote server. This part works fine but now I'm trying to compare the remote file size to the local file size.
If the two don't match then I want to prompt the user to enter yes or no
I've added the read command, but the script never pauses and asks the question. why ?
This is my test code
while IFS=',' read -r downloadfiles; do
case "$downloadfiles" in
AA)
filetoget="$downloadfiles.tar.gz"
;;
BB)
filetoget="$downloadfiles.zip"
;;
esac
sizeoffile=`curl -sI "http://server.com/$filetoget" | awk '/Content-Length/{sub("\r","",$NF); print $NF}'`
curl -O http://server.com/$filetoget
localsizeoffile=`stat --print="%s" $filetoget`
if [ "$localsizeoffile" -ne "$sizeoffile" ]; then
echo "error..."
read -p "Continue (y/n)?" CONT
if [ "$CONT" = "y" ]; then
echo "yaaa";
else
echo "booo";
fi
fi
done < filelist
Can anyone advise what I've done wrong. thanks
Update..
I've intentionally set it so a local file will have the wrong size so I can test.. I get the error error...
but not the prompt asking if they want to continue.. any ideas
Fixed Typo
You can use this (inspired by dank's answer):
read -p "Continue (y/n)?" CONT </dev/tty