-1

I have a cron task with "printf":

#!/bin/bash

# ..........
printf "hello\n"
# ..........

It runs once in N hours. However, in /var/log/syslog I don't see any logs with "hello" at all. Why not?

13
  • 2
    Try checking your mail box with the mail command.
    – Davidw
    Jun 23, 2018 at 16:56
  • 2
    It depends on who is running the script. If it's you, then it should show up in your mail. (note that this assumes that sendmail is installed and configured for local system mail.)
    – Davidw
    Jun 23, 2018 at 17:02
  • 1
    @Davidw what if it's not me and it's not installed? what does it have to do with email at all!
    – Jimku
    Jun 23, 2018 at 17:15
  • 1
    superuser.com/questions/306163/…
    – Davidw
    Jun 23, 2018 at 18:09
  • 2
    Back up a second. Why do you think it should be in syslog? It shouldn't. Email as @Davidw is saying, is the default output. We have no idea how your system is up. What does any of this have to do with managing systems? You're looking for basics on how cron works. Serverfault isn't for learning the basics of Linux.
    – user143703
    Jun 23, 2018 at 18:10

1 Answer 1

3

The designers of cron assumed that cron users would appropriately direct output (stdout & stderr) and, thus, any output that was not redirected to either a file or to another process was likely a mistake.

Their election was to forward via sendmail all spurious (i.e., un-redirected) output to the owner of the cron job.

If you check /var/log/syslog, you should find an entry like:

 Jun 26 22:18:01 sys0af3e3 CRON[16529]: (CRON) info (No MTA installed, discarding output)

The program typically called by cron is /usr/sbin/sendmail, but you can verify which is used in your implementation by running:

 strings /usr/sbin/cron | grep -i '^/.*mail'

If you were to create /usr/sbin/sendmail (it should be executable) with the contents:

 echo "####################" >> /tmp/mail.out 2>&1
 date >> /tmp/mail.out 2>&1
 cat >> /tmp/mail.out 2>&1

then run:

 systemctl restart cron  #this must be run as root

you would find your missing output appended to the file /tmp/mail.out after every run.

Don't forget to remove /usr/bin/sendmail and restart cron after you finish your test.

Not the answer you're looking for? Browse other questions tagged .