This question already has an answer here:

Following is my crontab entry

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

Got no error in log file also

Shell Script

#! /bin/sh

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

Script run perfectly when I use in command line as under

sh /FinalSync.sh  $(date --date="5 days ago" +%d_%m_%Y)

marked as duplicate by Gilles linux Oct 17 '16 at 11:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


cron converts % to newline for any crontab entry. You need to escape the %s with \:

* * * * *  /FinalSync.sh "$(date --date="5 days ago" +\%d_\%m_\%Y)"
  • changed but didn't work.. – HDev007 Oct 17 '16 at 10:56
  • I wonder what's the history of using the percent sign for that... – ilkkachu Oct 17 '16 at 10:56
  • Got 126 error code in log file – HDev007 Oct 17 '16 at 10:59
  • @ilkkachu probably just carried over from printf and similar functions. – terdon Oct 17 '16 at 11:00
  • 1
    @HadoopDev007 yes, I understand that but that is a different problem. So, ideally, accept this answer which solved your original issue and then ask a new question about the 126 error. – terdon Oct 17 '16 at 11:17

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