A script program to Auto-upload Motion Detection videos of Motion Linux to free ftp server DriveHQ , using Rclone and get email alerts on Ubuntu 19.04

Joined
Sep 20, 2018
Messages
10
Reaction score
11
Location
Sri Lanka
It is assumed that the Motion Linux is installed on the Linux PC

Please refer my blog on “How to use Motion Linux 4.2.2-1 to create a CCTV system on Ubuntu 18.10 , 64 bit with a Web Cam and Hikvision IP Cam” to get the details of installing Motion Linux

A brief introduction of main activities in this tutorial is given below.

To upload motion detection events , immediately after the occurrence , to the DriveHQ cloud , the Rclone software is used . For emailing the alert Mutt on Ubuntu is used

The DriveHQ FileManager free for Android is used to view uploaded video on the android phone

The email messages are viewed using Aol app on the phone

The following main software have to installed for above purpose

Motion Linux

Mutt

Rclone

Note :- The installation procedure of Motion Linux and Mutt has already being explained in detail in the following blog post

How to Email Motion Detection videos of Motion Linux( 3.2.2) using Mutt on Ubuntu 19.04



We will have to signup and get DriveHQ and Aol mail free accounts first.

The DriveHQ is the best free ftp cloud server with 5GB free storage, which is more than enough to save our motion detection videos generated by Motion Linux .



following details are required for the configuration of rclone

ftp host address of DriveHQ is ftp.drivehq.com

ftp port is 21



Screenshot from 2019-07-27 18-30-38


Figure:-1. web login view of DriveHQ cloud



Installation and configuring Rclone

On the Ubuntu terminal run

sudo apt install rclone

Screenshot from 2019-07-28 22-28-12


Figure:-2. installing rclone

Screenshot from 2019-07-28 22-28-33


Figure:- 3. installing rclone

rclone config



Screenshot from 2019-07-29 10-19-15


Screenshot from 2019-07-28 22-29-51

Figure:- 4. making ftp drive in rclone to upload files ( you can assign any name)



Figure:- 5. selecting the cloud connection or connection method







Screenshot from 2019-07-28 22-33-29




Figure:- 6. selecting ftp connection on ftp.drivehq.com host, port 21 , and entering user name and password of free DriveHQ cloud account



Screenshot from 2019-07-28 22-38-19


Figure:- 7. finishing configuration of rclone


Screenshot from 2019-07-28 22-40-00

Screenshot from 2019-07-28 22-39-36

Figure:- 7b rclone configuration file at ~/.config/rclone

Screenshot from 2019-07-28 22-46-02


Figure:- 8. Testing the ftp upload using rclone to see whether a file can be uploaded to DriveHQ cloud account using rclone copy command

Screenshot from 2019-07-28 21-58-54


Figure:- 9. scripts in camera4 (USB camera)

Making a script file MotionTest.sh mainly to

1. sort latest motion detection video stored in ~/Videos/motion and to copy to ~/Videos/motion/sub/

2 . upload to DriveHQ using rclone with ftp facility

3. send email alerts of the latest motion detection events to Aol account using Mutt



Screenshot from 2019-07-28 22-02-19


Figure:- 10. script file of MotionTest.sh

The scripts in MotionTest.sh are appended below
#!/bin/bash
rm ~/Videos/motion/sub/.
cp -p "ls -dtr1 ~/Videos/motion/*.mkv | tail -1" ~/Videos/motion/sub
rclone copy ~/Videos/motion/sub/*.mkv ftpdrv:camera

echo "web link of the folder where the videos are stored in drivehq.com" | mutt -s "Motion is detected see the link" -- bkjaya1952@aol.com










The script file MotionTest.sh is saved in /home/bkjaya1952/Documents/ folder

Then go to /home/bkjaya1952/Documents/ and run on the terminal

chmod +x MotionTest.sh




Note:-web link of the folder where the videos are stored in drivehq.com has to be replaced accordingly .Please see the link underlined in red in the figure below



Screenshot from 2019-07-29 00-11-17




Figure:- 11. Getting web link of the folder where the videos are stored in drivehq.com

Email alerts on Aol mail

When a motion is detected, MotionTest.sh script in camrea4.conf is activated.

The scripts in MotionTest.sh do the following activities

1. delete all files in the sub directory /Videos/motion/sub/ before coping the latest video

script command rm ~/Videos/motion/sub/.

2. select the latest motion detection video saved by Motion Linux in
the directory ~/Videos/motion/ and copy it to the sub directory
~/Videos/motion/sub/



script command cp -p "ls -dtr1 ~/Videos/motion/*.mkv | tail -1" ~/Videos/motion/sub

3. upload the latest motion detection video copied in to ~/Videos/motion/sub/ to the camera directory of DriveHQ cloud using ftp facility in rclone

script command rclone copy ~/Videos/motion/sub/*.mkv ftpdrv:camera

4. email the alert of the latest motion detection event to Aol account using Mutt (with the access link of video in DriveHQ cloud )

script command echo “web link of the folder where the videos are stored in drivehq.com” | mutt -s “Motion is detected see the link” — bkjaya1952@aol.com



Screenshot from 2019-07-29 09-37-18


Figure:- 12. received email alerts on Aol mail



Screenshot from 2019-07-29 09-37-36




Figure:- 13. email the alert of the latest motion detection event with the access link of video in DriveHQ cloud

Viewing motion detection videos on mobile phone

Install DriveHQ FileManager on the phone and login to the DriveHQ account to see the automatically uploaded motion detection videos

Screenshot_2019-07-27-21-45-18


Figure:- 14. viewing files on DiveHQ cloud using DriveHQ FileManager on a mobile phone

Screenshot_2019-07-27-21-46-07


Figure:- 15.viewing motion detection events pushed to DriveHQ cloud using DriveHQ FileManager on a mobile phone

Screenshot_2019-07-27-19-41-08.png




Figure:- 17. viewing videos in DriveHQ cloud using mobile phone

The DriveHQ which is having ftp facility in free plan seems to be the best cloud to save motion detection events of CCTV open source software like Motion Linux and Zoneminder .
 
Top