Email syslog

From Ever changing code

We are going to use mutt command line tool to email attached syslog on regular basis.

  • Install mutt
 sudo apt-get install mutt
  • Verify you can send attachment test-email.txt within the email message
mutt -a test-email.txt -- < /dev/null
< /dev/null sends nothing to email body
-- is required as per man page
Attach a file to your message using MIME. When attaching single or multiple files, separating filenames and recipient addresses with "--" is mandatory, e.g. mutt -a image.jpg -- addr1 or mutt -a img.jpg *.png -- addr1 addr2. The -a option must be placed at the end of command line options.
  • Compress all logs to temporary file /tmp/dmk1-cradlepoint.tgz
tar -zcvf /tmp/dmk1-cradlepoint.tgz /var/log/dmk1_cradlepoint.log*
  • Email using mutt
echo | mutt -s "Your_WHID Syslog" -a /tmp/dmk1-cradlepoint.tgz --
  • Ver1 Create script
tar -zcvf /tmp/dmk1-cradlepoint.tgz /var/log/dmk1_cradlepoint.log*
echo | mutt -s "DMK1 Syslog" -a /tmp/dmk1-cradlepoint.tgz --
  • Ver2 single command email attachment (working)

Install sharutils to

sudo apt-get install sharutils
gzip -c syslog.tar.gz /var/log/syslog | uuencode syslog.tar.gz | mail -s "Compressed syslog attachment"

Probably need adding /tmp and then removing

  • add to daily cron jobs

work in progress

  • ready script

Script is being tested

Script name
Router syslog are zipped from /var/log/netgear.log* to one file ~/syslog/netgear-DATE.tar.gz
NOW=$(date +"%m-%d-%Y")
tar -czf ~/syslog/netgear.$NOW.tar.gz /var/log/netgear.log* 
echo | mutt -s "DSS1 $NOW Netgear syslog" -a ~/syslog/$FILE --

Added to cron.daily, user's scripts are run from /home/username/

sudo apt-get install gnome-schedule

List a user cron jobs

crontab -u username -l

Example output, script will be run every day at 11:10am and any STDOUT will be suppressed to /dev/null

10 11 * * * ~/ >/dev/null 2>&1 # JOB_ID_1

Edit user cron tab

crontab -e
GNU nano 2.2.6                                  File: /tmp/crontab.nBbRuz/crontab
45 17 * * * ~/ >/dev/null 2>&1 # JOB_ID_1