3

Crontab Entry:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * *  /FinalSync.sh $(/bin/date --date="5 days ago" +\%d_\%m_\%Y) || echo $? >> log

OR

 * * * * *  /FinalSync.sh $(date --date="5 days ago" +\%d_\%m_\%Y) || echo $? >> log

Tried both

Got 126 as error code in log file

Shell Script

#! /bin/sh

source=/Source/$1
destination=/Destination
folderParam=$(basename $source)
if /usr/bin/rsync -avh -r $source $destination; then
   cp /FolderCopyStatus/Success   /Status/Success_$folderParam
else
   cp /FolderCopyStatus/Failure   /Status/Failure_$folderParam
fi

The result of ls -l @ilkkachu

-rw-r--r-- 1 root root 299 Oct 17 16:20 /FinalSync.sh
3

As suggested in my comment on your previous question, error code 126 seems to imply you do not have permission to execute the script or a command inside it (see http://tldp.org/LDP/abs/html/exitcodes.html). This is weird though because crontab is supposed to be a root process. try the following:

chmod +x /FinalSync.sh

That could help. Otherwise, the problem might come from your cp command (maybe you're trying to write somewhere you should not?). Also try \cp to avoid aliasing (so that whoever launches the script, it will always behave the same).

  • Could be a users crontab though – Jakob Lenfers Oct 17 '16 at 15:17
  • I don't think even root can execute a file that doesn't have +x bits. – ilkkachu Oct 17 '16 at 16:13
  • @valentin tried this but didn't work – HDev007 Oct 18 '16 at 5:58
  • @HDev007 If your cron is not executed by root, do chmod a+x /FinalSync.sh instead. And in any case, verify that /FinalSync.sh is executable. Your ls -l output shows that it is not. – xhienne Mar 21 '17 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.