LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-11-2005, 10:02 AM   #1
XaViaR
Member
 
Registered: Dec 2004
Distribution: RHEL, CentOS, SuSE
Posts: 170

Rep: Reputation: 31
Need Help with a Script


Hello,

I have created the following script. My purpose of this script is to "cat info from /var/log/messages then filter for the following keywords: ssh* and the current date. Once I gather this info I would then mail it to myself.

The problem I am running into...there is no data being cat'ed out. Hmm...Could someone look this over then let me know what I need to change?

Thanks in advance for your help!

-Xaviar

P.S.
I am running this script as root! :-)

# -- Bellow is the script --

#! /bin/bash

#-------------------------------------------------------------
# This scripts sends fail sshd attempts to root's mail account
#-------------------------------------------------------------

# Variables
#
DATE=`date +'%b %e'`

# Searching for the ssh info filtered by date and ssh*
#
cat /var/log/messages |grep ssh* |grep %DATE | mail -s "SSH Log-Failed Attempts" myemail@something.com

Last edited by XaViaR; 11-11-2005 at 10:06 AM.
 
Old 11-11-2005, 10:15 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
How about this...
cat /var/log/messages | grep -e ssh* | grep "$DATE"

Last edited by homey; 11-11-2005 at 10:25 AM.
 
Old 11-11-2005, 10:17 AM   #3
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Re: Need Help with a Script

Quote:
Originally posted by XaViaR

cat /var/log/messages |grep ssh* |grep $DATE | mail -s "SSH Log-Failed Attempts" myemail@something.com
Also you don't need the * after ssh

Try the line in the command line first before putting it into a script.

Code:
DATE=`date +'%b %e'`
cat /var/log/messages |grep ssh
see what it gives
then

Code:
cat /var/log/messages |grep ssh|grep $DATE
then the complete one
 
Old 11-11-2005, 10:32 AM   #4
XaViaR
Member
 
Registered: Dec 2004
Distribution: RHEL, CentOS, SuSE
Posts: 170

Original Poster
Rep: Reputation: 31
it worked!

Thanks for your help!

Last edited by XaViaR; 11-11-2005 at 10:34 AM.
 
Old 11-11-2005, 10:46 AM   #5
XaViaR
Member
 
Registered: Dec 2004
Distribution: RHEL, CentOS, SuSE
Posts: 170

Original Poster
Rep: Reputation: 31
homey,

Why did I need to use quotes "" ? --> |grep "$DATE"
Do you know why single quotes '' or `` did not work?
 
Old 11-11-2005, 10:55 AM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Because the out put of DATE=`date +'%b %e'` has spaces in it.
You see that situation a lot in scripts to rename mp3 or jpg files.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 04:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10: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
Open Source Consulting | Domain Registration