Using Wget with Amcrest IP Camera

So I know I can use Wget to pull a still image from my Amcrest Cameras. I wanted to set up a script that would do that, however, save it to a specific place on my server. Then tie all that into a motion sensor so that an image is saved when motion is detected.

Ultimately, I would love for it to grab a still image around every three seconds for say fifteen seconds when motion is detected. But I can try and tackle that later if no one has any ideas on that. First, however, I would like to just get the image and save it to a specific location. Anyone have any ideas?

So I worked out the script file to loop over the wget command:

#!/bin/bash

x=1
while [ $x -le 3 ]
do
  wget http://admin:[email protected]/cgi-bin/snapshot.cgi_$(date +"%m%d%Y-%H%M%S")
  x=$(( $x + 1 ))
  sleep 5
done

What I need now is how to save the images to a specific location.

After some googling and testing I was able to work out how to specify wget saving to a particular directory:

#!/bin/bash

x=1
while [ $x -le 3 ]
do
  wget -P /path/to/store/files/ http://admin:[email protected]/cgi-bin/snapshot.cgi_$(date +"%m%d%Y-%H%M%S")
  x=$(( $x + 1 ))
  sleep 5
done

So now to see if I can figure out how to tie that script to a motion sensor. Off we go.

So I have a question for something I have not quite been able to figure out. The image files are saved with the filename that begins with snapshot.cgi. How would I go about removing that (it has to be part of the url to trigger the image capture) once the file is saved but preserve the date format?

Basically, I want the file names to be mmddyy_hhmmss.jpg. I fixed the .jpg part, easy enough, but have not figured out how to strip the snapshot.cgi.

How about something like this?

#!/bin/bash

x=1
while [ $x -le 3 ]
do
  wget -P /path/to/store/files/ http://admin:[email protected]/cgi-bin/snapshot.cgi
  mv /path/to/store/files/snapshot.cgi /path/to/store/files/snapshot$(date +%m%d%Y-%H%M%S).jpg
  x=$(( $x + 1 ))
  sleep 5
done
1 Like

Awww snap. I forgot about the move command. I completely over thought that, I was thinking I was going to need to use regex or something similar.

So I can see the image from my camera at http /admin:admin@cameraip:port/cgi-bin/snapshot.cgi

But when I use wget as

wget http /admin:admin@url:port/cgi-bin/snapshot.cgi -O test.jpg
I get
Resolving abc.com… 101.202.303.404
Connecting to … … … :<… connected.
HTTP request sent, awaiting response… 401 Unauthorized
HTTP request sent, awaiting response… 500 Internal Server Error

2019-01-25 12:40:53 ERROR 500: Internal Server Error.

Any ideas?

Sorry the links are mistyped because “new users can only post 1 url…”

I also understand that the format name:password@url is deprecated in http.

Does anyone know how to run this as a script? When I try using shell_command, I get bash error 127. I’ve tried including the full path of /bin/bash but no luck.

configuration.yaml:

shell_command:
amcrest_motion_detected: ‘/bin/bash ./config/scripts/wget_amcrest_cam.sh’

script:
amcrest_motion_detected:
alias: ‘amcrest motion detected’
sequence:
- service: shell_command.amcrest_motion_detected