Rclone crontab problem

crontab

* * * * * sh /home/rclone/log/rclone_cron.sh >/home/rclone/log/cron.log 2>&1

log file from crontab problem

/home/rclone/log/rclone_cron.sh: 6: /home/rclone/log/rclone_cron.sh: Syntax error: end of file unexpected (expecting "then")

script run rclone

#!/bin/bash

if pidof -o %PPID -x “rclone_cron.sh”; then
exit 1
fi
rclone copy --dry-run neungcoc013_TD1: neungcoc014_TD1: -vv --log-file "/home/log/rclone_1.log" &
exit

Help fix script run rclone.
Thank you everyone for the help.

Looks like it's just some basic syntax problem in your if-statement.
Here is an example syntax:

#!/bin/bash
read -p "Enter numeric value: " myvar
if [ $myvar -gt 10 ]
then
echo "OK"
else
echo "Not OK"
fi

So I would start by

  • adding [ ] brackets to the condition
  • I don't think you need the " ; " there either
  • That " & " at the end looks a bit out of place too...

But I am barely literate in bash, so these are just my best guesses :wink:

i test script

#!/bin/bash
if [ "$(pidof -o %PPID -x "rclone_cron.sh")" ] then
exit 1
fi
rclone copy --dry-run neungcoc013_TD1: neungcoc014_TD1: -vv --log-file "/home/log/rclone_1.log"
exit

#!/bin/bash
if [pidof -o %PPID -x "rclone_cron.sh]
then
exit 1
fi
rclone copy --dry-run neungcoc013_TD1: neungcoc014_TD1: -vv --log-file "/home/log/rclone_1.log"
exit

don't work :joy:

What is the error output now then?
Your second script looks ok to me at a glance - except that you need to add a second ( " )
in your condition "rclone_cron.sh

#!/bin/bash
if [pidof -o %PPID -x "rclone_cron.sh"]
then
exit 1
fi
rclone copy --dry-run neungcoc013_TD1: neungcoc014_TD1: -vv --log-file "/home/log/rclone_1.log"
exit

log file from crontab problem

/home/rclone/log/rclone_cron.sh: 7: /home/rclone/log/rclone_cron.sh: Syntax error: end of file unexpected (expecting "then")

I am too bad at bash to easily debug it for you lol, I think it is easier for me to just help you find what you need. Looks like this would be suitable for you?

if pidof -x $(basename $0) > /dev/null; then
  for p in $(pidof -x $(basename $0)); do
    if [ $p -ne $$ ]; then
      echo "Script $0 is already running: exiting"
      exit
    fi
  done
fi

Or otherwise I can tell you how to do a similar thing using lockfiles, because that is something I have made before. That would prevent more than 1 instance of any script to run at the same time. I assume that is your goal here...

Thank you very much. :heart_eyes:

Can you share it?

Of course!
Do you want an example for windows (batch) ?
or Linux (bash) ?

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.