I want to know how I can see exactly what the cron jobs are doing on each execution. Where are the log files located? Or can I send the output to my email? I have set the email address to send the log when the cron job runs but I haven't received anything yet.
相关问题
- I want to trace logs using a Macro multi parameter
- Error message 'No handlers could be found for
- convert logback.xml to log4j.properties
- Django management command doesn't show logging
- apache modules ap_log_perror is at a different lev
相关文章
- how do I log requests and responses for debugging
- Android Studio doesn't display logs by package
- Stacktrace does not print in Glassfish 4.1 Cluster
- Out of curiosity — why don't logging APIs impl
- Laravel log file based on date
- Java -How to get logger to work in shutdown hook?
- Codeigniter not logging
- Is there any way to remove the information line fr
cron
already sends the standard output and standard error of every job it runs by mail to the owner of the cron job.You can use
MAILTO=recipient
in thecrontab
file to have the emails sent to a different account.For this to work, you need to have mail working properly. Delivering to a local mailbox is usually not a problem (in fact, chances are
ls -l "$MAIL"
will reveal that you have already been receiving some) but getting it off the box and out onto the internet requires the MTA (Postfix, Sendmail, what have you) to be properly configured to connect to the world.will log all output from the cron job to /var/log/myjob.log
You might use
mail
to send emails. Most systems will send unhandledcron
job output by email to root or the corresponding user.There are at least three different types of logging:
The logging BEFORE the program is executed, which only logs IF the cronjob TRIED to execute the command. That one is located in /var/log/syslog, as already mentioned by @Matthew Lock.
The logging of errors AFTER the program tried to execute, which can be sent to an email or to a file, as mentioned by @Spliffster. I prefer logging to a file, because with email THEN you have a NEW source of problems, and its checking if email sending and reception is working perfectly. Sometimes it is, sometimes it's not. For example, in a simple common desktop machine in which you are not interested in configuring an smtp, sometimes you will prefer logging to a file:
There are some common sources of problems with cronjobs: * The ABSOLUTE PATH of the binary to be executed. When you run it from your shell, it might work, but the cron process seems to use another environment, and hence it doesn't always find binaries if you don't use the absolute path. * The LIBRARIES used by a binary. It's more or less the same previous point, but make sure that, if simply putting the NAME of the command, is referring to exactly the binary which uses the very same library, or better, check if the binary you are referring with the absolute path is the very same you refer when you use the console directly. The binaries can be found using the locate command, for example:
Be sure that the binary you will refer, is the very same the binary you are calling in your shell, or simply test again in your shell using the absolute path that you plan to put in the cronjob.
By default cron logs to /var/log/syslog so you can see cron related entries by using:
https://askubuntu.com/questions/56683/where-is-the-cron-crontab-log
Incase you're running some command with sudo, it won't allow it. Sudo needs a tty.
Here is my code: