From 18095754824d4b6390d839b1ef28d3419cefac14 Mon Sep 17 00:00:00 2001 From: zenjabba Date: Sun, 28 May 2017 11:46:48 -0400 Subject: [PATCH] more robust process checking this is a more robust processing checking process. --- rclone/rclone-upload.sh | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) 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