Actions

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 -- youremail@address.com < /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 -- youremail@address.com
  • Ver1 Create script emailsyslog.sh
!/bin/bash
tar -zcvf /tmp/dmk1-cradlepoint.tgz /var/log/dmk1_cradlepoint.log*
echo | mutt -s "DMK1 Syslog" -a /tmp/dmk1-cradlepoint.tgz -- youremail@address.com
  • 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" youremail@address.com

Probably need adding /tmp and then removing

  • add to daily cron jobs

work in progress

  • ready script

http://bash.cyberciti.biz/backup/backup-files-email-to-your-account/

Script is being tested

Concept
Script name email-netgear-syslog.sh
Router syslog are zipped from /var/log/netgear.log* to one file ~/syslog/netgear-DATE.tar.gz
#!/bin/bash
NOW=$(date +"%m-%d-%Y")
FILE="netgear.$NOW.tar.gz"
tar -czf ~/syslog/netgear.$NOW.tar.gz /var/log/netgear.log* 
echo | mutt -s "DSS1 $NOW Netgear syslog" -a ~/syslog/$FILE -- youremail@address.com

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 * * * ~/email-billion-syslog.sh >/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 * * * ~/email-syslog.sh >/dev/null 2>&1 # JOB_ID_1