Raspberry Pi ‐ Germination monitoring system - erynmcfarlane/StatsGenLabProtocols GitHub Wiki

Shell script for taking and uploading photos

This shell script takes a photo using the rpicam library, then uses rclone to upload the photo to Google Drive

#shell script for taking a picture using Raspberry Pi #1 and uploading it to Google drive

#set naming and destination parameters
date=$(date + "%Y-%m-%d-%H.%M.%S")
extension="jpg"
new_filename=${date}.${extension}

#take a picture with rpicam-still, save it with a datetime-based filename
rpicam-still -o /home/jleblanc/Pictures/Pi1-Pics/${new_filename}

#copy that picture to google drive using rclone
rclone copy /home/jleblanc/Pictures/Pi1-Pics PiDrive1:RPi-Stuff/Pi1-Pics

Notes

  • The naming parameters set each photo file to be named with the date and time it was taken.
  • rclone copy copies all files contained within a specified folder (/path/to/folder) to a remote (Google Drive) specified by Name of Remote on rclone:Folder
  • rclone copy does not copy over files with matching names (i.e. it won't double up on files that are already uploaded)
  • The names of the folder pathways and remote drive will be specific to the user and the raspberry pi configuration

crontab for executing the shell script at a set interval

* * * * * /bin/bash -c "/home/jleblanc/Scripts/RP1-shell.sh > /home/jleblanc/Scripts/RP1-shell.log 2>&1"

Notes

  • The /bin/bash command tells cron to execute the shell script using bash, which is important for correctly executing rpicam and rclone commands
  • The time interval at which the photo is taken is set by adjusting the asterisks, which correspond to Minute/Hour/Day of Month/Month/Day of Week
    • Leaving all asterisks as-is (i.e. * * * * *) indicates that the task should be executed every minute of every hour of every day...etc.
    • e.g. 30 5 * * * indicates for the task to be executed at 05:30 every day
    • e.g. 0 12 * * 1 indicates to execute at 12:00 every Monday
  • You need to indicate the absolute path of the script you want to execute; cron has different defaults for HOME directory and file PATHs