Search code examples
cron

Why doesn't my little cron job find the shell command?


 34 7 * * * test_cron > /tmp/stdout.log 2> /tmp/stderr.log

And my executable 'test_cron' contains:

echo "Test cron job ..."

now=$(date)
echo "Cron job update completed at $now"

But when it executes, the stderr is below:

tmp % tail /tmp/std*           
==> /tmp/stderr.log <==
/bin/sh: test_cron: command not found

==> /tmp/stdout.log <==

Does it mean it can't find the /bin/sh? How to fix it?


Solution

  • Few things you can check

    1. Does the test_cron have an executable flag? If it doesn't you can run the following command in the dir where the script exists.
    chmod +x test_cron
    
    1. Does the test_cron script exists in the $PATH?

    PS: I would recommend writing the absolute path to your test_cron script in your cron config. In this case you won't need to add the script to your $PATH