Forum Replies Created
-
AuthorPosts
-
philsto
ParticipantYeah, it looks like it…. We’ll try that, thanks.
Phil
philsto
ParticipantHey there,
It’s our understanding that –N option on wget just tells it to continue saving the file in the same spot, otherwise, if you download the same file to a directory twice, regardless of whether you have deleted the original, it will name the new one “filename.1”. This would make it difficult to write a script for, since the file name would constantly be changing.
Is that a misunderstanding of the function, or does it have some other effect which may have gotten in the way?
Phil
philsto
ParticipantHere is the script….
My misunderstanding, the script does not require root under ssh. it runs fine as any user. However, it also creates 0 Kb files when initiated from terminal on the server itself…
#!/bin/bashHOST_IP=0.0.0.0
IMAGE_URL=http://0.0.0.0/jpg/1/image.jpg
IMAGE_DIR=/Volumes/Data/Webserver/File
W_DIR=/scripts
SLEEP_TIME=30
HOST_REACHABLE=1grab()
{D=`date +%F%p`
echo “Checking the server.”
ping -c 1 $HOST_IP &> /dev/null
if [ $? = 0 ]; then
HOST_REACHABLE=1echo “Getting image file.”
/opt/local/bin/wget -N $IMAGE_URL > $W_DIR/image.jpg
if [ $? = 0 ]; then
echo “Archiving…”
mv $W_DIR/current.jpg $W_DIR/bak/image.$D.jpg
if [ ! -s $W_DIR/image.$D.jpg.gz ];
then gzip -c $W_DIR/bak/image.$D.jpg > $W_DIR/bak/image.$D.jpg.gz
fi
rm $W_DIR/bak/image.$D.jpg
echo “Updating..”
mv $W_DIR/image.jpg $W_DIR/current.jpg
ditto $W_DIR/current.jpg $IMAGE_DIR/current.jpg
echo “Done.”
else
echo “Error: Image Not Found”
HOST_REACHABLE=0
fielse
echo “Error: Host Unreachable”
HOST_REACHABLE=0
fi
}while [ $HOST_REACHABLE = 1 ]; do
grab
echo “Sleeping…”
sleep $SLEEP_TIME
doneexit 0
-
AuthorPosts
Recent Comments