I have a Daemon coded in C to copy a file from local to remote using RSYNC and update the same file after every 5 second.
Everything works fine but when the while loop has executed for say 10 to 15 times RSYNC fails.
Here is the segment of code:
#define SHELLSCRIPT "\
#! /bin/bash \n\
rsync -azh /my_daemon_test -e 'ssh -p 2222' username@domainname.com:~ \n\
"
syslog(LOG_NOTICE, "Successfully started daemon\n");
while(1) {
syslog(LOG_NOTICE, "daemon in while loop : %d\n", flag);
sys_ret = system(SHELLSCRIPT);
syslog(LOG_NOTICE, "RSYNC Executed %d\n", sys_ret);
sleep(5);
flag++;
}
Log
Dec 18 00:07:08 localhost ./mydaemon[26384]: daemon in while loop : 10
Dec 18 00:07:09 localhost ./mydaemon[26384]: RSYNC Executed 0
Dec 18 00:07:14 localhost ./mydaemon[26384]: daemon in while loop : 11
Dec 18 00:07:15 localhost ./mydaemon[26384]: RSYNC Executed 0 <==== Success
Dec 18 00:07:20 localhost ./mydaemon[26384]: daemon in while loop : 12
Dec 18 00:07:20 localhost ./mydaemon[26384]: RSYNC Executed 65280 <==== Failed
Dec 18 00:07:25 localhost ./mydaemon[26384]: daemon in while loop : 13
Dec 18 00:07:26 localhost ./mydaemon[26384]: RSYNC Executed 65280
Need help to maintain the consistency.
Thanks