How to make 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
It is assumed that the Motion Linux is installed on the Linux PC
Please refer my blog on “
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
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
sudo apt install rclone
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
#!/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
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 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
Please refer my blog on “
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
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
Figure:-1. web login view of DriveHQ cloud
Installation and configuring Rclone
On the Ubuntu terminal runsudo apt install rclone
Figure:-2. installing rclone
Figure:- 3. installing rclone
rclone config
Figure:- 4. making ftp drive in rclone to upload files ( you can assign any name)
Figure:- 5. selecting the cloud connection or connection method
Figure:- 6. selecting ftp connection on ftp.drivehq.com host, port 21 ,
and entering user name and password of free DriveHQ cloud account
Figure:- 7. finishing configuration of rclone
Figure:- 7b rclone configuration file at ~/.config/rclone
Figure:- 8. Testing the ftp upload using rclone to see whether a file
can be uploaded to DriveHQ cloud account using rclone copy command
Figure:- 9. scripts in camera4 (USB camera)
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
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
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/sub3. 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
Figure:- 12. received email alerts on Aol mail
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
Figure:- 14. viewing files on DiveHQ cloud using DriveHQ FileManager on a mobile phone
Figure:- 15.viewing motion detection events pushed to DriveHQ cloud using DriveHQ FileManager on a mobile phone
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 .
Comments
Post a Comment