Operating System - HP-UX
1753797 Members
7898 Online
108805 Solutions
New Discussion юеВ

Re: how can i get last 10 lines of a log mailed to me?

 
SOLVED
Go to solution
bob the spod
Occasional Advisor

how can i get last 10 lines of a log mailed to me?

Daily I have to cut n paste an entry of a log report into a windows folder for admin purposes.

I would like to set up an automated e mail sent to myself which would contain the last 10 lines of the daily report.

whats the best solution?

My train of thought is going crontab, mailx
but I dont know the correct syntax to set it up...

cheers for any help out there
Bob

Happy Monday to yer
you make me feel like dancing (gonna dance the night away!)
5 REPLIES 5
Robert-Jan Goossens
Honored Contributor
Solution

Re: how can i get last 10 lines of a log mailed to me?

Hi,

Cronab will do fine,

/usr/bin/tail -b 10 syslog.log | /usr/bin/mail yourname@foo.com

Regards,
Robert-Jan
T G Manikandan
Honored Contributor

Re: how can i get last 10 lines of a log mailed to me?

00 11 * * * a.sh

a.sh would contain

mailx -s "Daily report" bob@bob.com < `tail -10 dailyreport.txt`

bob the spod
Occasional Advisor

Re: how can i get last 10 lines of a log mailed to me?

Robert Im trying your method
so far Im receiving an e amil which is great but there is no data or any text at all in the e mails body

any chance you could break down each part of the line please

cheers
bob
you make me feel like dancing (gonna dance the night away!)
Robert-Jan Goossens
Honored Contributor

Re: how can i get last 10 lines of a log mailed to me?

Hi,

TGM method should work also, but hust tried my own.

03 12 * * 1-5 /usr/bin/tail -10 /var/adm/syslog/syslog.log | /usr/bin/mail myname@Foo.com 2>&1

worked good.

Regards,
Robert-Jan

Re: how can i get last 10 lines of a log mailed to me?

Bob,

Here is something I wrote regarding this to answer an earlier question. Rather than edit the previous post (It's starting to feel pretty late in the day), just insert the "/usr/bin/tail -10 /var/adm/syslog/syslog.log" command as needed. I only wanted to include this in the thread since it also incorporates the use of the subject field, and provides a different way to do this. I'm pretty sure there are cleaner methods, but this is one I have used, and works rather well.

Good Luck,
Chris


*** previous entry ***

The cron command should look like this:

/usr/sbin/ioscan -fnC lan > /tmp/ioscan.out ; elm -s "Subject of Message" username@companyname.com < /tmp/ioscan.out ; rm /tmp/ioscan.out

Because of the need for the subject line, the elm command was used. This along with the redirection of the command line will work with most commands, as long as the full path is specified.


If you would like to get the result of a command like "date" in the subject field, command

substitusion can be used. Make the line look like this:

/usr/sbin/ioscan -fnC lan > /tmp/ioscan.out ; elm -s "Subject of Message `date`" username@companyname.com < /tmp/ioscan.out ; rm /tmp/ioscan.out

A tick, not a single quote, surrounds the date command. The tick is usually the character under the tilde (~) symbol on the keyboard. You can also use other commands such as `hostname` for even more description.


So to add a cron job of the "who -R" command to send an e-mail every hour to the root account of abc.com with the subject that included the current date, you would edit the crontab file as follows:

# crontab -e

then add:

0 * * * * /sbin/who -R > /tmp/who.out ; elm -s "Who output for `date`" root@abc.com < /tmp/who.out ; rm /tmp/who.out