Saturday, January 24, 2009

Writing to syslog using shell scripts

logger is a simple command to write a string to /var/log/syslog. For example:

$ logger -i "This is a test string"

$ logger -is -p local0.info -f /var/log/syslog This is another test string
    -i includes the PID
    -s sends a copy to stdout (the screen)
    -p is the priority. See the available priorities at 'man logger'
    -f is the log to append to
And here's how to log from a crontab:
* * * * * /usr/bin/logger -i crontab test

No comments:

Post a Comment