Script to parse an access-list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to parse an access-list
# 22  
Old 07-11-2008
Quote:
Code:
 awk '!/deny|remark|permit|MyAccessList/{exit}
/MyAccessList/,/no_such_record/' file

It seems like it doesn't find the pattern... For your reference I pasted the access-list where I do the test on:

Code:
 
[root@bsd01 /home/me]# more qos.htm
ip access-list extended YourAccessList1
   remark this is your security rule
   permit host 192.168.0.1 any
ip access-list extended MyAccessList
   remark Do not allow Jones subnet to telnet out
   deny tcp host 171.69.2.88 any eq telnet
   remark Do allow me to telnet out
   permit tcp host 171.69.2.89 any eq telnet
ip access-list extended YourAccessList2
   remark this is your security rule
   permit host 192.168.0.1 any

[root@bsd01 /home/me]# awk '{if(/deny|remark|permit|MyAccessList/){print} else {exit}}' qos.htm
[root@bsd01 /home/me]#
[root@bsd01 /home/me]# awk '!/deny|remark|permit|MyAccessList/{exit}
> /MyAccessList/,/no_such_record/' qos.htm
[root@bsd01 /home/me]#

# 23  
Old 07-11-2008
I modified my previous post, it was wrong, sorry ...
Chek the last one:

Code:
nawk '/MyAccessList/ { f = 1 }
f && !/deny|remark|permit|MyAccessList/ { exit }
f, 0' file

Are you sure that the different access-lists are not always separated by the string "ip access-list"?
# 24  
Old 07-11-2008
Quote:
Originally Posted by radoulov
Yep, my fault ..., work in progress Smilie

This one Smilie
Use nawk please!

Code:
awk '/MyAccessList/ { f = 1 }
f && !/deny|remark|permit|MyAccessList/ { exit }
f, 0' file

This works!!!! Thanks everybody, really appreciated...

Radoulov, can you please explain a bit what it does? The result is there, but it would be nice to know a bit how it is working as well... Smilie

Thanks again!
# 25  
Old 07-11-2008
Quote:
Originally Posted by radoulov
I modified my previous post, it was wrong, sorry Are you sure that the different access-lists are not always separated by the string "ip access-list"?
Yes; the last entry of the last access-list can be followed by any router command...
# 26  
Old 07-11-2008
Sure:

Code:
/MyAccessList/ { f = 1 }

When the current record matches the pattern "MyAccessList" set the variable f to 1 (f is for flag, you can use another valid variable name if you wish, for AWK everything but 0 and null is true). So from that record f will be true.

Code:
f && !/deny|remark|permit|MyAccessList/ { exit }

Here we chek if f is true AND (logical and) the record doesn't match the listed patterns (deny, remark ...) , then exit.

Code:
f, 0

A pair of patterns (the pattern could be an expression) separated by a comma, specify a range of records. So we want to print the range from where f is true to 0 (false, never, open range, but we exit before the new access list becose of the previous pattern/action pair Smilie).

I feel like there is a much better solution though ..., perhaps someone else will try, time for coffee now Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed/awk script to parse list of bandwidth rules

Hello all gurus, I have a long list of rules as below: 20 name:abc addr:203.45.247.247/255.255.255.255 WDW-THRESH:12 BW-OUT:10000000bps BW-IN:15000000bps STATSDEVICE:test247 STATS:Enabled (4447794/0) <IN OUT> 25 name:xyz160 addr:203.45.233.160/255.255.255.224 STATSDEVICE:test160... (3 Replies)
Discussion started by: sb245
3 Replies

2. Shell Programming and Scripting

Help parse comma separated list

I have a list of files with the same name, but they have a different date stamp in the name. I can find the first file, but I need to find the second file. I am using this information to create a variable I use later. Here is a example of how I find the first file. "ls -mr... (11 Replies)
Discussion started by: NoMadBanker
11 Replies

3. Homework & Coursework Questions

Parse a Web Server Access Log

1. The problem statement, all variables and given/known data: Write a parser for a web server access log that will provide the statistics outlined below. Remember to format your output in a neat form. You may complete this assignment with one Awk script or a shell script using a combination of... (6 Replies)
Discussion started by: codyhazelwood
6 Replies

4. Shell Programming and Scripting

Splitting a list @list by space delimiter so i can access it by using $list[0 ..1..2]

EDIT : This is for perl @data2 = grep(/$data/, @list_now); This gives me @data2 as Printing data2 11 testzone1 running /zones/testzone1 ***-*****-****-*****-***** native shared But I really cant access data2 by its individual elements. $data2 is the entire list, while $data,2,3...... (1 Reply)
Discussion started by: shriyer
1 Replies

5. Solaris

List users who have administrative access

Hi , Could you please give me the commands for the following. 1.list users who have direct access to solaris database at os-level 2.list users who have administrative access at os-level in solaris Please also let me know how to figure out these specific users i need from a... (6 Replies)
Discussion started by: James777
6 Replies

6. Shell Programming and Scripting

How to parse a list of data to find the missin stats.

HI ALL, Thanks for helping me with my last post. :b: I have one more doubt, i want to parse a set of data. which is consisting of some values that occured in particular period of time. And when i parse down if there is a missing time period then it should show the two rows between which the... (3 Replies)
Discussion started by: asirohi
3 Replies

7. UNIX for Dummies Questions & Answers

How can I get the list of files if I have root access?

Hi, I'm very new and dumb in linux. What I do is: I use putty to connect to the linux server. I use auth.komtels.ru as a connection line root and oP04Koh0 as a password port 6262, and SSH protocol now I need to get the list of the files, how could I do it? (1 Reply)
Discussion started by: linuxbeginner
1 Replies

8. Solaris

Command for access control list

Hi, I want to set access control list on folders but it should be recursively, any Idea? command (1 Reply)
Discussion started by: manoj.solaris
1 Replies

9. Shell Programming and Scripting

Access Control List

Hey all, I have a directory (own by user: b; group: grpB) which I want a user (user: a; group: grpA) to be able to read and execute from, I wonder if I should add user a to this particular directory's ACL or that I would add group grpB to user a's subgroup? I would like to know the difference... (3 Replies)
Discussion started by: mpang_
3 Replies

10. UNIX for Dummies Questions & Answers

list of books I have access to

I have another question. I have access to the books listed below, however I know that not all of them are the lates and greatest and some are over 10 years old. So the question is are most of these books still a good idea to read. Or should I try and pick up the latest and greatest editions? ... (5 Replies)
Discussion started by: bru
5 Replies
Login or Register to Ask a Question