Created
November 1, 2019 17:11
-
-
Save mauron85/0db722fc934810218afa17ffa514e4e5 to your computer and use it in GitHub Desktop.
Grab camera snapshot and upload to remote server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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