Sponsored Content
Full Discussion: Compare lines and execute
Top Forums Shell Programming and Scripting Compare lines and execute Post 302212614 by ntenz on Tuesday 8th of July 2008 02:45:06 AM
Old 07-08-2008
Quote:
Originally Posted by Annihilannic
Something like this perhaps? (untested)
Code:
grep "Invalid user root" /var/log/messages|cut -c 68-79 | sort | uniq -c | awk '$1 > 3 { print $2 }' >> /etc/config/ipsec_deny.conf

I'd guess you'd want to make it a bit fancier though, to check whether the IP already exists, etc.
Hi Annihilannic,

I messed around yesterday and got this:

#!/bin/sh
set -x
B=1:
rm /home/banip/output.1
touch /home/banip/output.1

grep "Invalid user root" /var/log/messages|cut -c 68-79 > /home/banip/output.1

#If same entry is there more than 3 times

tmp1="`head -n 1 /home/banip/output.1`"
tmp2="`sed -n 2p /home/banip/output.1`"
tmp3="`sed -n 3p /home/banip/output.1`"

if [ $tmp1 == $tmp2 ] && [ $tmp1 == $tmp3 ]
then

A="`cat output.1| head -n 1`"

echo "$B""$A" >> /etc/config/ipsec_deny.conf
echo "$A is not banned"

I know its ugly and by far bulletproof - I will try to use your line and mess around. Always nice with inspiration Smilie

Thanks for your time much appreciated!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I get an if statement to execute based on number of lines in a file?

I need to have an if statement in a script to run if there are certain processes running. Easiest way I can see to do this is to run a ps and grep the results based on what I am looking for: $ ps -ef | grep wtrs --- webtrend 5046 1 0 May 12 ? 0:28 /webtrends/versions/6.1/wtrs_ui... (6 Replies)
Discussion started by: LordJezo
6 Replies

2. Shell Programming and Scripting

Trying to compare lines in 2 files

Hello, I am new to scripting and need some help. In looking at other posts on this forum, I came up with the following logic. I cannot figure out why I am getting names of files of the current directory in my echo output. Scenario: message file has a line containing the version. Version.txt... (2 Replies)
Discussion started by: brdholman
2 Replies

3. Shell Programming and Scripting

How to execute the rest of the code after commenting multiple lines?

Hi, As I have seen in this forum how to comment multiple lines in the script, but it does not work properly for me. It is blocking the code but it does not execute the rest of the codes. This is my code #! /usr/bin/ksh month='date +"m%"' : << Comments Block if || then echo "inc =... (12 Replies)
Discussion started by: Yamini Thoppen
12 Replies

4. Shell Programming and Scripting

Execute output lines

I have a command (not shell script) that general several lines of output like this... scp /var/lib/mysql/jitu/email.* root@172.29.0.218:/root/pitu/ scp /var/lib/mysql/jitu/orders.* root@172.29.0.218:/root/pitu/ I tried adding xargs but it did not work. -exec was not tried because I guess it... (3 Replies)
Discussion started by: shantanuo
3 Replies

5. Shell Programming and Scripting

Execute the Output Lines.

Hi, My Script looks like this #! /bin/ksh cd /usr/SrcFiles/ADD; while read line do d=`echo $line|cut -d'.' -f1` echo $d".XML" >> XML_File_List.txt out=`echo "gunzip -c -S .ZIP $d.ZIP > $d.XML;"` echo $out per=`echo "chmod ugo+rwx $d.XML;"` echo $per done <ZIP_File_List.txt and the... (5 Replies)
Discussion started by: naveen.kuppili
5 Replies

6. Shell Programming and Scripting

Compare lines within a file

could someone write a short script which is able to take a text file input and compare lines 1 and 2, 3 and 4, 5 and 6 ... ... until the end of the file. And to prompt if the lines are not equal. Thank you! (10 Replies)
Discussion started by: c_lady
10 Replies

7. Shell Programming and Scripting

Compare values for a pattern match and execute script

Here in the input file 23:59:13,devicename,21,server1,700 23:59:13,devicename,22,server2,200 23:59:13,devicename,23,server3,200 23:59:13,devicename,24,server4,200 23:59:13,devicename,25,server5,200 23:59:13,devicename,26,server6,200 23:59:13,devicename,27,server7,200... (6 Replies)
Discussion started by: necro98
6 Replies

8. Shell Programming and Scripting

Count, compare, execute ...

I'm working on a script that needs to execute only after directory B is equal in file count to directory A. It needs to check dir B every 5 min or so and when the file count is equal to A, it executes a script. I'm thinking of using wc -w but I'm not sure how to put it together. Any help... (7 Replies)
Discussion started by: scribling
7 Replies

9. UNIX for Dummies Questions & Answers

Compare lines in 2 files

I have 2 files with exactly the same information (with header and separated by ";") and what I would like to do is print (for both files!) the columns that are different and also print the "key" column that is equal in the 2 files For example, if File1: key1;aaa;bbb;ccc key2;ddd;eee;fff... (4 Replies)
Discussion started by: mvalonso
4 Replies

10. Shell Programming and Scripting

Compare lines between two files

I have two files I need to compare these two files and take the lines that are common in both the files and consider the line present in second file for my further processing I have used "Awk" along with "FNR and NR" but that is not working gawk -F= ' > FNR==NR {a=$1; next}; > ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies
cachefslog(1M)						  System Administration Commands					    cachefslog(1M)

NAME
cachefslog - Cache File System logging SYNOPSIS
cachefslog [-f logfile | -h] cachefs_mount_point DESCRIPTION
The cachefslog command displays where CacheFS statistics are being logged. Optionally, it sets where CacheFS statistics are being logged, or it halts logging for a cache specified by cachefs_mount_point. The cachefs_mount_point argument is a mount point of a cache file system. All file systems cached under the same cache as cachefs_mount_point will be logged. OPTIONS
The following options are supported. You must be super-user to use the -f and -h options. -f logfile Specify the log file to be used. -h Halt logging. OPERANDS
cachefs_mount_point A mount point of a cache file system. USAGE
See largefile(5) for the description of the behavior of cachefslog when encountering files greater than or equal to 2 Gbyte ( 2**31 bytes). EXAMPLES
Example 1: Checking the Logging of a directory. The example below checks if the directory /home/sam is being logged: example% cachefslog /home/sam not logged: /home/sam Example 2: Changing the logfile. The example below changes the logfile of /home/sam to /var/tmp/samlog: example# cachefslog -f /var/tmp/samlog /home/sam /var/tmp/samlog: /home/sam Example 3: Verifying the change of a logfile. The example below verifies the change of the previous example: example% cachefslog /home/sam /var/tmp/samlog: /home/sam Example 4: Halting the logging of a directory. The example below halts logging for the /home/sam directory: example# cachefslog -h /home/sam not logged: /home/sam EXIT STATUS
The following exit values are returned: 0 success non-zero an error has occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
cachefsstat(1M), cachefswssize(1M), cfsadmin(1M), attributes(5), largefile(5) DIAGNOSTICS
Invalid path It is illegal to specify a path within a cache file system. SunOS 5.10 7 Feb 1997 cachefslog(1M)
All times are GMT -4. The time now is 05:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy