Snapshot script for Dahua camera

marigo

Getting the hang of it
Joined
Dec 24, 2016
Messages
136
Reaction score
47
Location
Netherlands
Just wanted to share a script to make a snapshot from a unix machine.

Goal was to make a snaphot every day at 12:00pm so that after a year you will have 365 or 366 pictures (if the server has no down time) which can be looked back in a short period to see season changes. :)
(or other thing ofcourse)

I use my raspberry PI for this and copy the file to my Synology NAS. I have used the public key on the raspberry copied to the NAS to do a secure copy "scp" from the raspberry to the NAS. without the need for username/password. (See this how-to)

Code:
#!/bin/bash

today=`/bin/date '+%d-%m-%Y__%H-%M-%S'`;        #Used to generate unique filename
IP="IP address or hostname"                      #IP address Camera
NAS="IP address or hostname"                    #NAS

# Start snapshot
wget 'http://'$IP'/onvifsnapshot/media_service/snapshot?channel=1&subtype=0?' -O /tmp/$today.jpg

# Send snapshot to Network disk through SCP
scp /tmp/*.jpg root@$NAS:/absolute/path/cam1

# Remove temporary snapshot file
rm /tmp/*.jpg

# Done!
use a cronjob to execute the script at 12:00pm
Code:
0 12 * * * /absolute/path/to/script
I had to turn off "Onvif authentication" to get it working.
 

Westy87

n3wb
Joined
Jul 13, 2023
Messages
2
Reaction score
0
Location
Brisbane
Just wanted to say I wish I saw this days ago before I went down the rabbit hole of trying to get scheduled snapshots from a camera.

I realised I can run the wget command direct from cron on my NAS server and then access it over smb from my PC later to build a time lapse.

/usr/local/bin/wget /usr/local/man/man1/wget.1.gz '' -O /path/to/store/snapshot/Cam3/$(date +"%y-%m-%d_%H%M%S").jpg --no-check-certificate
 
Top