commit c485fc4ff97c956121352df7baa00c05136a3262
parent 0407380b0d6555ea7eee58d5538b8f9ae5bcd3de
Author: Daniel Moch <daniel@danielmoch.com>
Date: Sun, 24 Dec 2017 07:31:54 -0500
Add crontab and related scripts
Diffstat:
3 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/.config/cron/crontab b/.config/cron/crontab
@@ -0,0 +1,28 @@
+# Edit this file to introduce tasks to be run by cron.
+#
+# Each task to run has to be defined through a single line
+# indicating with different fields when the task will be run
+# and what command to run for the task
+#
+# To define the time you can provide concrete values for
+# minute (m), hour (h), day of month (dom), month (mon),
+# and day of week (dow) or use '*' in these fields (for 'any').#
+# Notice that tasks will be started based on the cron's system
+# daemon's notion of time and timezones.
+#
+# Output of the crontab jobs (including errors) is sent through
+# email to the user the crontab file belongs to (unless redirected).
+#
+# For example, you can run a backup of all your user accounts
+# at 5 a.m every week with:
+# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
+#
+# For more information see the manual pages of crontab(5) and cron(8)
+#
+# m h dom mon dow command
+LANG=en_US.utf8
+DISPLAY=:0.0
+*/5 * * * * cd /home/djmoch/.config/forecastio && ./weather.py
+*/15 * * * * ~/.config/cron/vdirsyncer.sh > ~/.local/var/log/vdirsyncer 2>&1
+*/15 * * * * ~/.config/cron/photosync.sh > ~/.local/var/log/photosync 2>&1
+
diff --git a/.config/cron/photosync.sh b/.config/cron/photosync.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+echo "Beginning photo sync at $(date)"
+
+# Only do the following if nextcloud.danielmoch.com is reachable
+if ping -c 1 nextcloud.danielmoch.com > /dev/null 2>&1
+then
+ echo "nextcloud.danielmoch.com reachable. Proceeding."
+else
+ echo "nextcloud.danielmoch.com NOT reachable. Exiting."
+ exit -1
+fi
+
+# Mount the WebDAV folder and set so only we can read it
+if mount /mnt/nextcloud > /dev/null 2>&1
+then
+ echo "NextCloud WebDAV successfully mounted. Setting permissions."
+ chmod 700 /mnt/nextcloud
+
+ # Rsync from WebDAV to ~/Photos (unidirectionally for now, in order to
+ # preserve server space)
+ echo "Syncing Photos from WebDAV to ~/Photos"
+ rsync -aq /mnt/nextcloud/Photos /home/djmoch/
+
+ # Finish by unmounting the WebDAV folder
+ echo "Unmounting nextcloud.danielmoch.com"
+ umount /mnt/nextcloud > /dev/null 2>&1
+else
+ echo "NextCloud WebDAV mount FAILED. Exiting."
+ exit -2
+fi
+
+echo "Completed photo sync at $(date)"
diff --git a/.config/cron/vdirsyncer.sh b/.config/cron/vdirsyncer.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+echo "Beginning sync on $(date)"
+vdirsyncer sync
+echo "Completed sync on $(date)"