0

My script:

#!/bin/sh
var=$(date)
/usr/bin/sed -i "s|DATE=.*|$(/home/my/script $var)|g" /path/file

Running this script manually works perfectly. As soon as it is ran from cron, in particular the sed portion of the script, will fail.

The variable will hold the correct content under the cron environment. Only search/replace fails.

  • 1
    In what way does the search/replace fail? does it replace things it should not, or not replace things that it should? what is /home/my/script? – steeldriver Oct 15 at 22:53
  • The usage of /home/my/script $var provides a single value output that is what sed is replacing in front of DATE= It doesn't work by removing the entire DATE= line completely. Not something I can replicate manually. – t988GF Oct 15 at 22:57
  • 6
    Well my guess is that /home/my/script relies on some part of the environment that is present in your interactive shell, but is not present in cron's execution environment. Perhaps redirecting your cron command's output / error streams to a log file will help to troubleshoot it. – steeldriver Oct 15 at 23:24

Your Answer

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

Browse other questions tagged or ask your own question.