Shell script returns 126 exit code from crontab
21,424
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).
Related videos on Youtube
Author by
HDev007
Updated on September 18, 2022Comments
-
HDev007 almost 2 years
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
-
Jakob Lenfers over 7 yearsCould be a users crontab though
-
ilkkachu over 7 yearsI don't think even root can execute a file that doesn't have +x bits.
-
HDev007 over 7 years@valentin tried this but didn't work