I have a VM cluster with 3 nodes on CentOS7 and one node on RHEL7. There is a directory where rsync is enabled /mnt/<server_IP>/portal/wso2telcohub-3.0.2/repository/deployment/server/synapse-configs/default/api/ incrontab is set as below.

$ incrontab -l
/mnt/<server_IP>/portal/wso2telcohub-3.0.2/repository/deployment/server/synapse-configs/default/api/ IN_MODIFY,IN_ATTRIB,IN_CREATE,IN_DELETE /mnt/rsync/rsync-for-carbon-depsync.sh

rsync script with debug enabled

#!/bin/sh -ex
#source folder
#Destination folder
LOG=/log/rsync/carbon-rsync-logs/"log-local-$(date +%Y%m%d_%H%M%S).log"

echo "entered the script" >> $LOG

#keep a lock to stop parallel runs
echo "entered the flock" >> $LOG
flock -e 10
echo "Obtained the lock" >> $LOG
echo " ========== $(date -Iseconds) Lock acquired by local thread <server_IP>< =========== " >> $LOG
rsync --delete -arv $portal   $gateway  >>  $LOG
) 10> /var/rsync/.rsync.lock
echo " ========== $(date -Iseconds) Release Lock acquired by local thread <server_IP> =========== " >> $LOG

Below is the log file

entered the script
entered the script

Basically, whatever the change done on portal should reflect on gateway. I created a temp file in portal directory. But it doesn't reflect in gateway directory. This is only for the new RHEL 7 VM. Old CentOS 7 VM works fine with same script.

  • What debugging have you attempted? Can you confirm that your script is triggered by incrond when a file is created? (I see your "entered the script" but is that on the working system or the non-working system? Do the lines correspond with your tests or are they picking up something else?) Commented May 6, 2020 at 10:46
  • 1
    Debugging: just the echos. Yes, scrip is triggered by incrond. "entered the script" is from the non working system. Lines corresponding to my test Commented May 6, 2020 at 11:02
  • You need to identify why your script can't write entered the flock to the logfile. Permissions on /var/rsync/.rsync.lock maybe? What I'd do is put exec 2>/tmp/errors as the second line of the script, and investigate that for error messages. Commented May 6, 2020 at 12:59
  • @roaima: Thanks a lot for the tip. I checked /var/rsync/.rsync.lock. But there is no rsync directory inside /var for RHEL 7, for CenOS 7, I have the specified file above. How can we proceed? Commented May 6, 2020 at 14:53

1 Answer 1


I advised you to enable error reporting to a log file /tmp/errors by adding a new command at line two. Extending this a little, we get this modification that captures expected output and unexpected errors to a single file, /tmp/output:

#!/bin/sh -ex
exec >/tmp/output 2>&1

#source folder

In a production environment one would write to a better defined log file, or even use the system logger (man logger for details).

The shell -e flag causes it to exit as soon as it executes a command that returns a non-success status (non-zero exit code). The error log will capture the output generated as a consequence of any error just as the shell exits. The -x flag enables tracing - also to the log file.

In a comment you determined that, "there is no rsync directory inside /var for RHEL 7".

So, the reason your script is not working on RHEL 7 is because you have not created this directory that the script requires. The script tries to write to /var/rsync/.rsync.lock but it cannot do so because the parent directory does not exist.

The solution is to create the directory and ensure that the UID that executes your script can write to it. Better still, modify the script to create the directory if it doesn't already exist, or to report this error in some manner that can be captured and made available to a real person.

  • Thanks friend. It worked. Commented May 6, 2020 at 15:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .