Skip to content

Instantly share code, notes, and snippets.

@mauron85
Created November 1, 2019 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauron85/0db722fc934810218afa17ffa514e4e5 to your computer and use it in GitHub Desktop.
Save mauron85/0db722fc934810218afa17ffa514e4e5 to your computer and use it in GitHub Desktop.
Grab camera snapshot and upload to remote server
# Grab snapshot from camera and upload via HTTP post
post_url="https://myserver/upload.php?token="
camera_url="http://192.168.89.146/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=wuuPhkmUCeI9WG7C&user=guest&password=guest123"
start_hour=6
end_hour=18
now=$(date +"%Y-%m-%d-%H-%M-%S")
year=$(echo "$now" | awk -F'-' '{ printf "%s", $1 }')
month=$(echo "$now" | awk -F'-' '{ printf "%s", $2 }')
day=$(echo "$now" | awk -F'-' '{ printf "%s", $3 }')
time=$(echo "$now" | awk -F'-' '{ printf "%s%s%s", $4, $5, $6 }')
hour=$(echo "$now" | awk -F'-' '{ printf "%s", $4 }')
file_name="camera_$year$month$day$time.jpg"
if [ "$hour" -ge "$end_hour" ] || [ "$hour" -lt "$start_hour" ]; then
echo "skip upload"
exit 0
fi
curl -s $camera_url | curl -F "snapshot=@-;filename=$file_name" $post_url
# Grab snapshot from camera and upload via ftp
now=$(date +"%Y-%m-%d-%H-%M-%S")
year=$(echo "$now" | awk -F'-' '{ printf "%s", $1 }')
month=$(echo "$now" | awk -F'-' '{ printf "%s", $2 }')
day=$(echo "$now" | awk -F'-' '{ printf "%s", $3 }')
time=$(echo "$now" | awk -F'-' '{ printf "%s%s%s", $4, $5, $6 }')
hour=$(echo "$now" | awk -F'-' '{ printf "%s", $4 }')
dir="/tmp/snapshots"
file="camera_$year$month$day$time.jpg"
url="http://192.168.89.146/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=wuuPhkmUCeI9WG7C&user=guest&password=guest123"
server=
username=
password=
start_hour=6
end_hour=18
if [ "$hour" -ge "$end_hour" ] || [ "$hour" -lt "$start_hour" ]; then
echo "skip upload"
exit 0
fi
mkdir -p $dir
wget -O "$dir/$file" $url
lftp \
-u "$username,$password" \
-e "set ftp:ssl-allow no; \
mkdir -f /public_html/cam/$year; \
mkdir -f /public_html/cam/$year/$month; \
mkdir -f /public_html/cam/$year/$month/$day; \
put -O /public_html/cam/$year/$month/$day $dir/$file;bye" \
$server
rm $dir/$file
# Grab snapshot from camera and upload via HTTP post
post_url="https://myserver/upload.php?token="
camera_url="http://192.168.89.146/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=wuuPhkmUCeI9WG7C&user=guest&password=guest123"
dir="/tmp/snapshots"
start_hour=6
end_hour=18
now=$(date +"%Y-%m-%d-%H-%M-%S")
year=$(echo "$now" | awk -F'-' '{ printf "%s", $1 }')
month=$(echo "$now" | awk -F'-' '{ printf "%s", $2 }')
day=$(echo "$now" | awk -F'-' '{ printf "%s", $3 }')
time=$(echo "$now" | awk -F'-' '{ printf "%s%s%s", $4, $5, $6 }')
hour=$(echo "$now" | awk -F'-' '{ printf "%s", $4 }')
file_name="camera_$year$month$day$time.jpg"
postfile="$dir/postfile"
if [ "$hour" -ge "$end_hour" ] || [ "$hour" -lt "$start_hour" ]; then
echo "skip upload"
exit 0
fi
mkdir -p $dir
printf '%s\n' $'--FILEUPLOAD\nContent-Disposition: form-data; name="snapshot"; filename="'$file_name'";' \
$'Content-Type: application/octet-stream' \
$'Media Type: application/octet-stream\n' > "$postfile" &&
wget -O - $camera_url >> "$postfile" &&
printf '%s\n' $'\n--FILEUPLOAD--\n' >> "$postfile"
wget -O - \
--header="Content-type: multipart/form-data boundary=FILEUPLOAD" \
--post-file="$postfile" \
$post_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment