LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE
User Name
Password
SUSE / openSUSE This Forum is for the discussion of Suse Linux.

Notices


Reply
  Search this Thread
Old 07-27-2015, 04:45 AM   #1
spande
LQ Newbie
 
Registered: Jul 2015
Posts: 6

Rep: Reputation: Disabled
Sending newly created log file from suse linux to outlook mail through command line


Hello All,

I want to send newly created log file from suse linux to outlook mail box through command line.
In my machine I have configured logrotate for 5 days and I want to send logrotate’s latest output compressed file to outlook mail box every day at 00:30 (as logrotate rotate file at 00:00).
Below is the 5 days file output from my machine.

Server_Health_Logs-20150726.gz
Server_Health_Logs-20150727.gz
Server_Health_Logs-20150728.gz
Server_Health_Logs-20150729.gz
Server_Health_Logs-20150730.gz

From these above files I want to send only newly created (latest) file to outlook mail, like in this case I want to send Server_Health_Logs-20150730.gz.

Thanks in advance..
Santosh Pande
 
Old 07-27-2015, 06:40 AM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Here's a suggestion:
1. Use the tail command to get the latest .gz log from the list
Code:
tail -1 health_logs.txt 
Server_Health_Logs-20150730.gz
2. Use sendmail to send that file as an attachment to the desired e-mail address.

3. Schedule cron to run the sendmail command at 00.30 every day.

Best regards,
HMW
 
Old 07-28-2015, 10:13 AM   #3
ember1205
Member
 
Registered: Oct 2014
Posts: 176

Rep: Reputation: 16
That's a very incomplete solution at best. Much of what you're proposing requires executing the commands manually because nothing supports use inside of a script (there's no variable setting going on and the filename isn't being referenced in any way by a variable).

The correct way to do this would be to use the "postrotate" configuration file option and call a secondary script to locate the file just created and then send it via sendmail. Since the full path to the original log file is passed to the secondary script, it will make it easy to locate the newest file as follows:

find / -amin +2 $1*.gz

The result will be the newest of the compressed files, created within the last two minutes. The original log filename will be passed to the script containing this command, and you'll need to set the result into a variable. Then call sendmail, referencing that variable as the file to attach.
 
1 members found this post helpful.
Old 07-28-2015, 10:21 AM   #4
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by ember1205 View Post
That's a very incomplete solution at best.
It wasn't a solution. It was a suggestion. The OP is more than welcome to use your suggestions instead.
 
Old 07-30-2015, 03:59 AM   #5
spande
LQ Newbie
 
Registered: Jul 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hello ember1205 and HMW,
Thank u for your concern..

ember1205,
I have tried this below script but its not working. (not sending mail to outlook)
My same code is working on redhat but not in suse.
suse version is:
SUSE Linux Enterprise Server 11 (x86_64)
VERSION = 11
PATCHLEVEL = 1

Below is my code.

/Server_Health_Logs
{
daily
rotate 5
dateext
compress
create 0600 root root
postrotate
mutt -s "Server Utilization Report" ****@******.com -a "${1}-$(date +Y%m%d)"
endscript
}

Thanks and Regards.
 
Old 07-30-2015, 07:32 AM   #6
ember1205
Member
 
Registered: Oct 2014
Posts: 176

Rep: Reputation: 16
Try providing the full path to mutt - it won't find it properly otherwise.

Also, your filename "creator" isn't giving it the proper name because there's no inclusion of the ".gz" extension. The parameter that's passed (the ${1} is the original filename of the log that gets rotated, not the newly created file. Honestly, don't know how it is working on RH at all if the code is the same.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending Mail from Command Line kc5hwb Linux - Newbie 14 05-15-2015 09:14 AM
[SOLVED] Sending mail from the command line hoholala Linux - Software 2 01-02-2014 09:07 PM
Sending mail from command line. alaios Linux - Software 8 03-07-2013 09:15 AM
Sending mail from command line Geert86 Linux - Server 10 11-30-2009 12:04 PM
Watch log file from command line and e-mail emgee3 Linux - General 1 11-23-2009 07:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE

All times are GMT -5. The time now is 01:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration