Exclude string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exclude string
# 1  
Old 01-29-2015
Exclude string

I would like to write a script to check the log , if any line in the log have the string in include_list.txt but do not have the string in exclude_list.txt , then send alert mail to administrator , as below example , the line 1 have the string "string 4" ( which is in include_list.txt ) but do not have anything in exclude_list.txt , then display line 1 only in alert mail .
Would advise how to write this script ? very thanks .

Code:
#vi exclude_list.txt
string 1
string 2
string 3

Code:
#vi include_list.txt
string 4
string 5
string 6

For example
============
Code:
xxx string 4 xxxstring 2
xxx string 4 xxxxxxxxxx
xxx string 4 xxxxxxxxxx
xxx string 4 xxxxxxxxxx
xxx string 4 xxxxxxxxxx
xxx string 4 xxxxxxxxxx
xxx xxxxxxx xxxstring 3


Last edited by ust3; 01-30-2015 at 04:06 AM.. Reason: Add CODE tags again.
# 2  
Old 01-30-2015
Hello

Please post such examples with in CODE tags, as demanded by the forum rules, and it is easier to differ between space, tabs, or even reckognize their existence.

What have you tried to parse the entries of either one of the *clude-lists?
What have you tried to send a mail to the admin?

Have you searched the forum for at least one of the two questions?

Thank you.

---------- Post updated at 16:22 ---------- Previous update was at 03:32 ----------

Well, thanks for applying the code tags.
Any attemps you made so far on your own?

Last edited by sea; 01-29-2015 at 10:56 PM..
# 3  
Old 01-30-2015
Does this one display the desired line(s)?
Code:
< example fgrep -f include_list.txt | fgrep -f exclude_list.txt

# 4  
Old 01-31-2015
thanks reply ,

it helps , I will finish the script myself , but if I have 10 servers , rather receive 10 alert mails , how to make 10 mails becomes one single mail , all servers can be connected in any method , ssh , telnet , ftp ... etc.

very thanks
# 5  
Old 01-31-2015
You could have a file with the server names and try something like this (not tested):


Code:
while read server
do
  ssh "$server" cat logfile
done < file_with_servernames | grep -vFf exclude_list.txt > /tmp/filtered_log

if messages=$(grep -Ff include_list /tmp/filtered_log); then
  echo "$messages" | mailx ....
fi


Last edited by Scrutinizer; 01-31-2015 at 08:09 AM..
# 6  
Old 01-31-2015
ssh -n ... otherwise it reads from stdin (the input file) just like the read.
This User Gave Thanks to MadeInGermany For This Post:
# 7  
Old 01-31-2015
Quote:
Originally Posted by Scrutinizer
You could have a file with the server names and try something like this (not tested):


Code:
while read server
do
  ssh "$server" cat logfile
done < file_with_servernames | grep -vFf exclude_list.txt > /tmp/filtered_log

if messages=$(grep -Ff include_list /tmp/filtered_log); then
  echo "$messages" | mailx ....
fi

thanks reply ,
the above script is check remote server log , it seem check 1 server only , right ?
if I want to access 10 servers to check its log , would advise how to do it ? thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Du exclude in Solaris

How do you exclude a filesystem using du command in solaris? for example /proc Tried this but its not working du -sk -d /* --exclude=/proc | sort -nr | cut -f2 | xargs du -sh | head - (1 Reply)
Discussion started by: jinslick25
1 Replies

2. UNIX for Dummies Questions & Answers

Du exclude in Solaris

How do you exclude a filesystem using du command in solaris? for example /proc Tried this but its not working du -sk -d /* --exclude=/proc | sort -nr | cut -f2 | xargs du -sh | head - in linux it is working. (2 Replies)
Discussion started by: jinslick25
2 Replies

3. Shell Programming and Scripting

Exclude certain folders

Hi Experts, Below is my shell script and it will move the files older than 90 days to archive mount. Now my new requirement is , I need to move some of the directory files older than 365 days. How can I achieve this. Simply I have DIR1 DIR2 DIR3 DIR4 I need to exclude DIR 2 and DIR 2... (5 Replies)
Discussion started by: arumugavelvelu
5 Replies

4. Shell Programming and Scripting

Exclude files in ls

Hi, I need to exlucde the files which are present in exclude.txt from a directory exlcude.txt AUZ.txt AUZ.chk NZ.txt NZ.chk tried with below code but not working ls -ltr | grep -v `cat exclude.lst` (9 Replies)
Discussion started by: rohit_shinez
9 Replies

5. Shell Programming and Scripting

To exclude a string from monitoring

Hi below is my current scripting which will monitor for any errors in the application logfile="/tmp/application.log" output=$(grep "ERROR" $logfile) if then echo "found- send email" else echo "not found" fi Now I wanted the script not to send the email for one of the... (12 Replies)
Discussion started by: ajothi
12 Replies

6. Shell Programming and Scripting

Exclude a file or not in

Hi Gurus. I have a directory and i receive many files with extension .log. I processed the file as i get it. i want to process all the files except one which i know i don't want to process. cd /backup/temp/rajesh/PACS #--- directory , under this i have below files... (1 Reply)
Discussion started by: guddu_12
1 Replies

7. Ubuntu

[Solved] Using Find with an exclude/exclude file

I am familiar with using tar and exclude/include files: tar zcf backup.dirs.tgz --files-from=include.mydirs --exclude-from=exclude.mydirs --no-recursion but was wondering if I could use find in the same way. I know that you can just specify the directories to exclude but my list is... (2 Replies)
Discussion started by: metallica1973
2 Replies

8. SCO

Tar exclude

Hi, We work on a UNIX SCO SCO_SV Release = 3.2v5.0.5. I have a folowing structure /u/usr/lpp /u/usr/lpp/SQL /u/usr/lpp/DIR2 I use following tar to backup the /u/usr/lpp directory cd /u/usr/lpp tar cvf /u/usr/backup/backup.tar . Now I want to exclude the subdirectory SQL. I... (2 Replies)
Discussion started by: haezeban
2 Replies

9. UNIX for Dummies Questions & Answers

Exclude list

Hi, I am trying to exclude "/web" directory from a server. I am able to login to the server, and this is the command it gives me: $ /usr/openv/netbackup/exclude_list bash: /usr/openv/netbackup/exclude_list: No such file or directory can anyone pls help me :confused: (3 Replies)
Discussion started by: decamposem
3 Replies

10. UNIX for Dummies Questions & Answers

Getting 'tar' to exclude

I want 'tar' to exclude certain dir's. tar cvf ............. ............ does the whole lot, but I want to exclude the 'log' dirs. (6 Replies)
Discussion started by: kuultak
6 Replies
Login or Register to Ask a Question