I will show you get started with sending mails from the Linux command line. Will also cover sending attachments from the command line. We will begin with the “mail” command.
First we need to test the sendmail application to be installed and working correctly executing the following command:
echo “This is the body of mail.” | mail -s “Subject” you@youremail.com
Other command line option:
-s subject Specify subject on command line.
-c email-address Mark a copy to this “email-address”, or CC.
-b email-address Send blind carbon copies to list. List should be a comma-separated list of names.
Below are few examples that you can use with the mail command:
mail -s “System Log” you@youremail.com
This command sends a message with a subject line of “System Log” and the text of the message read from the system logfile /var/log/messages.
df -h | mail -s “Disk Space” you@youremail.com
This command sends a message with a subject line of “Disk Space” an the text of the output read from command df -h.
free -m | mail -s “Free RAM” you@youremail.com
This command sends a message with a subject line of “Free RAM” an the text of the output read from command free -m.
Filtering emails
============
# cat /var/log/mail.log | grep ’11:[0-5][0-9]’ | grep ‘Jun 28’
# grep ‘smtpd\[.*client=’ /var/log/mail.log | wc -l
# grep ‘postfix/smtp\[.*status=sent’ /var/log/mail.log | grep -v ‘relay=127.0.0.1’
# cat /var/log/mail.log | grep ‘from’ | grep ‘Jul*’ | wc -l
# cat /var/log/mail.log | grep ‘to’ | grep ‘Jul*’ | wc -l
# tail -f /var/log/squid3/access.log | gawk ‘{print strftime(“%d/%m/%Y %H:%M:%S”, $1), $3, $7}’
# cat /var/log/mail.log | grep ‘from=<ewb*' | grep "Ja*" | wc -l
by Jurandir
Looking form “words” inside squid compressed files
=========================================
# zcat /var/log/squid3/access.log.1.gz | awk ‘{print $3 “-” $7 “-” $11}’ | grep face* | wc -l
# zcat /var/log/squid3/access.log.1.gz | awk ‘{print $3 “-” $7 “-” $11}’ | grep face*