Mac OS X

Automatically Emailing Logs

As I have mentioned in the past, you can send mail from the command line by initiating a telnet session into port 25 of a mail server. Provided you have setup Mail.app you can also email from the command line using the mail command. In the below command we’re going to pipe the contents of a log file into an email by reading the contents using a cat command. From the output of the cat command we’re then going to email the contents of the file to an email address, specifying the subject line of the email using the -s option of the ppp command:

cat /var/log/ppp.log | mail -s “ppp logs” krypted@mac.com

The mail command actually has a number of options and can be used interactively or as we did above.  In this example we really just looked at sending a log to the email address.  But you can also read and view mail, send mail and of course, delete messages.