Run a docker container command from synology crontab

Written by James McDonald

April 12, 2018

Use the information here to edit the /etc/crontab and then restart with synoservice -restart crond http://www.multigesture.net/articles/how-to-use-cron-on-a-synology-nas/

# /etc/crontab every 2 hrs at 15 minutes past
15  */2 *   *   *   root    /root/checkAws.sh

/root/checkAws.sh


#!/bin/sh

LOG=/root/checkAwsOutput.log
SEND_EMAIL=/root/sendEmail.sh
echo -n `date` > $LOG
docker exec ubuntu2 aws s3 ls --summarize --human-readable --recursive s3://myamazonbucket/Pictures | grep "Total Size:" >> $LOG 2>&1

$SEND_EMAIL

// stolen from synology forum
/root/sendEmail.sh


#!/bin/sh

taskname="AWS Upload Check Total Size";

out=$(/bin/echo "Email test output"); status=$?;
host=$(/bin/hostname);
[email protected]
[email protected]
source /etc/synoinfo.conf;
headers=`printf "From: %s - %s <%s>\r\n" "$host" "$mailfrom" "$eventuser"`;
if [ ${#eventmail2} -gt 0 ];
then
to=`printf "%s, %s" "$eventmail1" "$eventmail2"`;
else
to=$eventmail1;
fi;
outcome="failed";
if [ ${status} -eq 0 ];
then
outcome="been completed";
fi;
outcome=`printf "%s on %s has %s" "$taskname" "$host" "$outcome"`;
subject=`printf "%s %s" "$eventsubjectprefix" "$outcome"`;

DATE_AND_TOTAL_SIZE=$(/bin/cat /root/checkAwsOutput.log);

body=`printf "Dear user,\n\n%s\n\nTask: %s\n\nSincerely,\nSynology DiskStation\n\n" "$DATE_AND_TOTAL_SIZE" "$taskname"`;

/usr/bin/php -r "mail('$to', '$subject', '$body', '$headers');";
/usr/syno/bin/synodsmnotify "@administrators" "System Event" "${outcome}";


0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…