Home Forums OS X Server and Client Discussion Questions and Answers SSH and script weirdness

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #371671
    philsto
    Participant

    We 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

    #371672
    khiltd
    Participant

    What’s in the script and why does it need root privileges to copy a file?

    #371687
    philsto
    Participant

    Here 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/bash

    HOST_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=1

    grab()
    {

    D=`date +%F%p`

    echo “Checking the server.”

    ping -c 1 $HOST_IP &> /dev/null

    if [ $? = 0 ]; then
    HOST_REACHABLE=1

    echo “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
    fi

    else
    echo “Error: Host Unreachable”
    HOST_REACHABLE=0
    fi
    }

    while [ $HOST_REACHABLE = 1 ]; do
    grab
    echo “Sleeping…”
    sleep $SLEEP_TIME
    done

    exit 0

    #371692
    khiltd
    Participant

    What if you lose the -N option on wget?

    #371704
    philsto
    Participant

    Hey 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

    #371706
    khiltd
    Participant

    I think you’ve misread the documentation:

    [code]-N, –timestamping don’t re-retrieve files unless newer than local.[/code]

    #371709
    philsto
    Participant

    Yeah, it looks like it…. We’ll try that, thanks.

    Phil

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Comments are closed