I have created a script that uses curl to retrieve a CSV file from a public site and copy it to my server.
#!/bin/sh
INCOMING="http://www.example.jp/csv/ranking.csv"
OUTPUT="/var/www/html/csv/ranking.csv"
curl -s $INCOMING > $OUTPUT
My boss ordered that if the CSV file retrieved from the site is 0 bytes, it should not be overwritten.
I heard that, then I wrote a script that looks like this.
#!/bin/sh
INCOMING="http://www.example.jp/csv/ranking.csv"
OUTPUT="/var/www/html/csv/ranking.csv"
INCOMING_LENGTH=$(curl -L -s -o /dev/null -w '%{size_download}\n' $INCOMING)
if [ "$INCOMING_LENGTH" -ne "0" ]; then
curl -s $INCOMING > $OUTPUT
fi
What I want to ask is, how to skip csv output progress when curl response size equals zero by a single curl command.
In the script above, I am running the curl command twice, so even if I check the file size in the first curl command and make sure it is not zero bytes, if the file size is zero in the second curl command, it will generate a zero-byte CSV file.
This should rarely happen, but my boss is a perfectionist, so I want to eliminate the element of poking around.
Thank you!