LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Ned to send command output to email (https://www.linuxquestions.org/questions/programming-9/ned-to-send-command-output-to-email-770611/)

Thaidog 11-21-2009 07:01 AM

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?

bartonski 11-21-2009 09:30 AM

Quote:

Originally Posted by Thaidog (Post 3764856)
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.

Thaidog 11-21-2009 11:58 AM

Quote:

Originally Posted by bartonski (Post 3764953)
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!


All times are GMT -5. The time now is 07:40 PM.