I'm trying to run a cron job in an Apache Linux environment. Specifically, this is the cron job.

SHELL=/bin/sh PATH=/usr/local/bin:/usr/local/sbin * * * * * sh root/rsync.sh 

The rsync in question should synchronize several folders mounted on the Apache, run a single Python script, and copy that result to a new file. I've tested that the rsync works extensively, so I feel sure that the only issues are with the cron job. It looks mostly like this: (edited for privacy)

if [ -e rsyncjob.lock ] then echo "Rsync job already running...exiting" exit fi touch rsyncjob.lock #your code in here cd .. rsync -r A B rsync -r C D python3 <python-file> rsync <final file> cd root #delete lock file at end of your job rm rsyncjob.lock 

I keep getting the following error when testing the cron job manually with cron -f:

cron: can't lock /var/run/crond.pid, otherpid may be 23719: Resource temporarily unavailable

Restarting the cron service, and deleting the file listed in the error have both failed.

I've tried different routings but the most common failure is that the rsync source and destination get root appended to the correct location, and then the cron job fails.

How can I resolve this?

1

1 Answer

Your cron -f fails because of running system cron instance. Stop it systemctl stop cron if you are sure about that.

Also avoid using relative paths in cron jobs. for example

if [ -e rsyncjob.lock ] 

should be something like

if [ -e /var/<whatever>/rsyncjob.lock ] 

also fix cd .., rsync A B and other relatives.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.