Script to parse an access-list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to parse an access-list
# 8  
Old 07-10-2008
Quote:
Originally Posted by in2nix4life
You can also use sed this way so that if the number of lines following the line containing MyAccessList is unknown, they will all get printed until you hit the line containing YourAccessList:

sed -n '/MyAccessList/,/YourAccessList/{/YourAccessList/d;p;}' file

Hope this helps.
This is what I need (I don't know the amount of lines in my accesslist), but I also don't know the nale of the next accesslist...
So it should print all lines starting from "ip access-list extended MyAccessList" until it finds a line that doesn't start with remark or permit or deny. That is the only way to know my access-list is ended (access-lists can only start with these 3 words)...
Thanks for the help so far
# 9  
Old 07-10-2008
Quote:
Originally Posted by Franklin52
vgersh99,

This prints unwanted lines if f becomes negative.

Regards
So:

Code:
awk '/^ip access-list extended/{f=4}f&&f--' file

# 10  
Old 07-10-2008
Quote:
Originally Posted by philipz
This is what I need (I don't know the amount of lines in my accesslist), but I also don't know the nale of the next accesslist...
So it should print all lines starting from "ip access-list extended MyAccessList" until it finds a line that doesn't start with remark or permit or deny. That is the only way to know my access-list is ended (access-lists can only start with these 3 words)...
Thanks for the help so far
Could you post bigger sample and the desired output?
# 11  
Old 07-10-2008
...
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 YourAccessList
remark this is your security rule
permit host 192.168.0.1 any
...



I want to print the content of MyAccessList like this:

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




In pseudo-code, this would be something like:

find linenumber with word "MyAccesslist"
while linenumber+1 contains "remark/deny/permit"
print linenumber+1
wend

Hope this helps to clarify...
# 12  
Old 07-10-2008
Try this:

Code:
awk '
/MyAccessList$/{f=1}
f&&/^ip access-list extended/{exit}
f' file

Regards
# 13  
Old 07-10-2008
Quote:
Originally Posted by Franklin52
Try this:

Code:
awk '
/MyAccessList$/{f=1}
f&&/^ip access-list extended/{exit}
f' file

Regards
I don't have my BSD machine here to test now, but I don't think it will work.
From what I can read, you check until you find a line that starts with "ip access-list extended", but the end of the accesslist can be anything (except a line that starts with permit/deny/remark; this would mean that it is still the access-list)
So my guess is that I need to trigger these 3 words; if not found, the access-list has ended...
# 14  
Old 07-10-2008
Code:
awk '!/deny|remark|permit|MyAccessList/{exit}
/MyAccessList/,0' file

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