Friday, September 30, 2011

Send email in linux

In new walk-through environment, there are some configuration issues need look at application logs to see what is going on. SSH to application server (tomcat) and vi the application log is the common way. Ops team can alsomail the log file to other developers to analyze, so need sendmail. Luckily there is "sendmail" in Linux.

Command Line:

  1. Check if sendmail is running => ps ax | grep sendmail
  2. Check if sendmail is running => /etc/init.d/sendmail status
  3. Check sendmail listening info (IP and port) => netstat -tnlp | grep sendmail
  4. Send email (please use man mail for user guide)
    1. mail -s "Email subject" < /tmp/test.txt
    2. cat /tmp/test.txt | mail -s "Email subject"
    3. echo "The message in email body" | mail -s "Email subject"
    4. (df -h;free -m) | mail -s "Disk and Memory Info"
    5. less /proc/cpuinfo | mail -s "CPU Info" -c
Shell script:
#df -h | mail -s "disk space"
df -h > /tmp/mail_report.log
free -m >> /tmp/mail_report.log
mail -s "disk and RAM report" < /tmp/mail_report.log
rm -f /tmp/mail_report.log

No comments:

Post a Comment