Home › Forums › OS X Server and Client Discussion › Questions and Answers › SSH and script weirdness
- This topic has 6 replies, 2 voices, and was last updated 17 years, 1 month ago by
philsto.
-
AuthorPosts
-
February 26, 2008 at 10:58 pm #371671
philsto
ParticipantWe have created a script to capture an image from a webcam and deposit it into a folder so it is available to the web.
The script was created by a colleague who SSHd into the server and placed the script on the root level in a folder called scripts.
the script works flawlessly when he kicks it off as sudo from the SSH connection. It deposits a 50Kb file into the folder and all looks great.
When I initiate the script locally via sudo I also get a file in the folder. Problem is it’s 0Kb, and there’s no there there…
Looked at all the permissions, and they look all right…
Any ideas?
Thanks
Phil
February 26, 2008 at 11:11 pm #371672khiltd
ParticipantWhat’s in the script and why does it need root privileges to copy a file?
February 27, 2008 at 9:03 pm #371687philsto
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
February 27, 2008 at 11:30 pm #371692khiltd
ParticipantWhat if you lose the -N option on wget?
February 28, 2008 at 5:08 pm #371704philsto
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
February 28, 2008 at 8:02 pm #371706khiltd
ParticipantI think you’ve misread the documentation:
[code]-N, –timestamping don’t re-retrieve files unless newer than local.[/code]
February 28, 2008 at 8:35 pm #371709philsto
ParticipantYeah, it looks like it…. We’ll try that, thanks.
Phil
-
AuthorPosts
- You must be logged in to reply to this topic.
Comments are closed