diff --git a/rclone/rclone-upload.sh b/rclone/rclone-upload.sh index 4023961..3360d4f 100644 --- a/rclone/rclone-upload.sh +++ b/rclone/rclone-upload.sh @@ -4,8 +4,33 @@ # * * * * * /home/plex/scripts/rclone-upload.cron >/dev/null 2>&1 # modify line 20 config file location -if pidof -o %PPID -x "rclone-upload.cron"; then - exit 1 +#!/bin/bash + +PIDFILE=/tmp/rclone-upload.pid +if [ -f $PIDFILE ] +then + PID=$(cat $PIDFILE) + ps -p $PID > /dev/null 2>&1 + if [ $? -eq 0 ] + then + echo "Job is already running" + exit 1 + else + ## Process not found assume not running + echo $$ > $PIDFILE + if [ $? -ne 0 ] + then + echo "Could not create PID file" + exit 1 + fi + fi +else + echo $$ > $PIDFILE + if [ $? -ne 0 ] + then + echo "Could not create PID file" + exit 1 + fi fi LOGFILE="/home/plex/logs/rclone-upload.cron" @@ -20,4 +45,5 @@ if find $FROM* -type f -mmin +15 | read rclone move --config=/path/rclone.conf $FROM $TO -c --no-traverse --transfers=300 --checkers=300 --delete-after --min-age 15m --log-file=$LOGFILE echo "$(date "+%d.%m.%Y %T") RCLONE UPLOAD ENDED" | tee -a $LOGFILE fi +rm $PIDFILE exit