The Computer Oracle

Log of cron actions on OS X

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Bleepage Open

--

Chapters
00:00 Log Of Cron Actions On Os X
00:37 Answer 1 Score 1
00:59 Answer 2 Score 13
02:27 Accepted Answer Score 52
02:50 Answer 4 Score 0
02:59 Thank you

--

Full question
https://superuser.com/questions/134864/l...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#macos #osxsnowleopard #cron

#avk47



ACCEPTED ANSWER

Score 52


Much easier to simply add the following to /etc/syslog.conf :

cron.*      /var/log/cron.log

Then restart syslog

sudo launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plist

Tested and working on OSX 10.7.4




ANSWER 2

Score 13


I figured it how to log my cron job activity without switching each one over to launchd jobs.

The cron man page mentions -x options which enables "writing of debugging information to standard output." A side effect of this is that these also write basic information to standard error. Data sent to standard error is written to /var/log/system.log.

This results in data like this being written to /var/log/system.log:

debug flags enabled: misc
[42073] cron started
log_it: (user1 42084) CMD (/root/bin/mysql-backup)
log_it: (user1 42094) CMD (run-parts /etc/cron.hourly)

Since cron itself is launched by launchd, to enable this, I had to edit /System/Library/LaunchDaemons/com.vix.cron.plist so that it now looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.vix.cron</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/sbin/cron</string>
        <string>-x</string>
        <string>misc</string>
    </array>
    <key>KeepAlive</key>
    <dict>
        <key>PathState</key>
        <dict>
            <key>/etc/crontab</key>
            <true/>
        </dict>
    </dict>
    <key>QueueDirectories</key>
    <array>
        <string>/usr/lib/cron/tabs</string>
    </array>
    <key>EnableTransactions</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/var/log/cron.log</string>
</dict>
</plist>

I used -x misc here, but it didn't seem to matter which options I used. Adding the -x started the logging of job activity. I also added the StandardErrorPath to write to /var/log/cron.log instead of the default /var/log/system.log.

And then unload and reload this:

$ sudo launchctl
Password:
launchd% unload /System/Library/LaunchDaemons/com.vix.cron.plist 
launchd% load /System/Library/LaunchDaemons/com.vix.cron.plist 



ANSWER 3

Score 1


OSX now tends to use launchd rather than cron - Apple dev doc - so it might be there is nothing in cron to log.

Use launchctl to control the logging level of launchd. Som log info appears in system.log but more in the console app -> All messages




ANSWER 4

Score 0


At least on Yosemite, cron logs output as mail messages, so use the mail to read them.