Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment

"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 >>.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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