LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-21-2009, 08:01 AM   #1
Thaidog
Member
 
Registered: Sep 2002
Location: Hilton Head, SC
Distribution: Gentoo
Posts: 616

Rep: Reputation: 32
Question Ned to send command output to email


I need to run the following command as a cron job that will email me every day:

for ip in `awk '/Invalid user/ {print $10}' /var/log/secure |sort -u`; do echo "$ip : "`grep -c $ip /var/log/secure`; done

Can somebody tell me a simple way to add that to a shell script?
 
Old 11-21-2009, 10:30 AM   #2
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 443
Blog Entries: 1

Rep: Reputation: 47
Quote:
Originally Posted by Thaidog View Post
I need to run the following command as a cron job that will email me every day:

for ip in `awk '/Invalid user/ {print $10}' /var/log/secure |sort -u`; do echo "$ip : "`grep -c $ip /var/log/secure`; done

Can somebody tell me a simple way to add that to a shell script?
Code:
for ip in `awk '/Invalid user/ {print $10}' /var/log/secure |sort -u`; do echo "$ip : "`grep -c $ip /var/log/secure` | mail user@host -s 'subject here'; done
This assumes that you have outbound email set up on your machine.
 
Old 11-21-2009, 12:58 PM   #3
Thaidog
Member
 
Registered: Sep 2002
Location: Hilton Head, SC
Distribution: Gentoo
Posts: 616

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by bartonski View Post
Code:
for ip in `awk '/Invalid user/ {print $10}' /var/log/secure |sort -u`; do echo "$ip : "`grep -c $ip /var/log/secure` | mail user@host -s 'subject here'; done
This assumes that you have outbound email set up on your machine.
Oh that's it? Thanks it's working!
 
  


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
how to make root cron job to send email if there is output mirror51 Linux - Newbie 3 08-12-2009 02:01 AM
send an email of script output s_linux Suse/Novell 19 07-25-2009 04:47 AM
How to send command output to file?! mr_aliagha Linux - General 2 02-27-2009 02:06 PM
send output of mysql query to email within same script hattori.hanzo Linux - Newbie 2 12-03-2008 04:14 AM
how to send the output of cronjobs to another email address ? kirtikjr Linux - Software 1 07-12-2007 06:36 PM


All times are GMT -5. The time now is 05:54 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration