Search code examples
shellcroncron-task

Cron job does not run


Following is the entry in the crontab:

[email protected]
45 14 * * * /home/user/simple.sh

I've also done chmod +x on the simple.sh But the crontab does not run, it doesn't even send an email.

pgrep cron shows an Id. I also tried bouncing crond. But no luck! Could someone please point out the mistake here

The simple.sh script is:

#! /bin/bash
echo hello

Thanks


Solution

  • Since you are doing a echo within the cron job script, you need to capture its output somewhere.

    Your shebang and file mode (using chmod +x) are all right, so those aren't the issue here and running without /bin/sh should work fine.

    Try using the following to see the output in cron.log file (This runs every minute)

    * * * * * /home/user/simple.sh >> /home/user/cron.log
    

    Note that cron jobs run in separate subprocess shell, with reduced environment, so its output won't be visible on your terminal.

    Regarding sending of email - you need to have some mail package (like postman, mutt etc) configured for the cron daemon to send out error mails.