LinuxQuestions.org
Help answer threads with 0 replies.
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, 07:01 AM   #1
Thaidog
Member
 
Registered: Sep 2002
Location: Hilton Head, SC
Distribution: Gentoo
Posts: 637

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, 09: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: 48
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, 11:58 AM   #3
Thaidog
Member
 
Registered: Sep 2002
Location: Hilton Head, SC
Distribution: Gentoo
Posts: 637

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 01:01 AM
send an email of script output s_linux SUSE / openSUSE 19 07-25-2009 03:47 AM
How to send command output to file?! mr_aliagha Linux - General 2 02-27-2009 01:06 PM
send output of mysql query to email within same script hattori.hanzo Linux - Newbie 2 12-03-2008 03:14 AM
how to send the output of cronjobs to another email address ? kirtikjr Linux - Software 1 07-12-2007 05:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:01 AM.

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