This site is now 100% read-only, and retired.

XML Logo

Posted by rossen on Tue 29 Sep 2009 at 09:41
Tags: , , ,
I often find sysadmin mailboxes filled with thousands of un-read messages originating from the output of cronjobs. The messages are usually banal but interesting to keep for a while, thus the sysadmins file them and forget them, sometimes for years. Some sysadmins simply avoid their mailbox if it has 12,000 messages in it. Important warnings get ignored this way.

Here is a tip that will help to reduce the clutter of the sysadmin's mailbox: pipe the STDOUT (and optionally STDERR) of simple cronjobs into your system log using the logger(1) program which is part of the "bsdutils" package.

For example, suppose you have a job called "my-backup" that backs-up a directory and you want to keep the verbose-but-boring output "just in case". Instead of a specifying the cronjob in /etc/cron.d/backup as

@hourly root /usr/local/sbin/my-backup

redirect the standard output to the syslog with

@hourly root /usr/local/sbin/my-backup | logger -t my-backup

or, if the error messages are known to be non-urgent, redirect output AND errors to the syslog with

@hourly root /usr/local/sbin/my-backup 2>&1 | logger -t my-backup

The option "-t my-backup" will nicely tag each line with the string "my-backup", allowing one to easily grep the contents of /var/log.


Posted by rossen on Mon 14 Jul 2008 at 09:27
Tags: , , ,
While re-reading the man page for bash 3.1 (in etch) I discovered that one can have timestamps in the output of "history". Just set the HISTTIMEFORMAT environment variable like so:


...and "history" will give you output like:

536 2008-07-14 10:13:02 echo $HISTTIMEFORMAT
537 2008-07-14 10:13:50 cat /etc/profile.local
538 2008-07-14 10:14:52 history

The .bash_history will contain hash-commented timestamps as seconds since the epoch:

cat /etc/profile.local