On my current Debian setup, I have a file /var/log/mail.log which Dovecot, Postfix, and Spamassassin's spamd all output messages to. I know that the logger command can output to syslog, but is there some command that easily lets me output to the mail log from a bash script, or do I have to manually open it and append to it?


Turns out the stuff I was logging using logger was also being logged out to my /var/log/mail.log file anyway. I think this is becasue (on Debian anyway) the default logging configuration in /etc/rsyslog.conf defines the default log for the mail 'facility' to be that mail.log file, and my script was indeed logging to the mail 'facility'. This seems to make logger log both to mail.log and to syslog.


"Manually open and append" in a bash context is pretty simple:

mycommand >> /var/log/mail.log

Standard output from mycommand goes to the file. If you put this at the beginning of a script:

exec 1>&2&>> /var/log/mail.log

Standard output (1) & error (2) for everything in the rest of the script will be appended to the file.

If you want to initially truncate the file (ie, not append to pre-existing content), use > instead of >>.

  • Right, but looking at the other stuff that's been logged to mail.log, it has the exact same format as stuff that's been logged to syslog. Presumably some library is being used to output that, rather than each line's string being manually constructed. Is there no way to generate this log line string from bash? – Jez Jan 19 '13 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.