Re: using arrays in my bash script, having problems
From: erik (ewitkop90_at_hotmail.com)
Date: 02/13/05
- Next message: erik: "grepping for pattern, and then deleting ALL the following lines after the pattern"
- Previous message: Chris F.A. Johnson: "Re: using arrays in my bash script, having problems"
- In reply to: Chris F.A. Johnson: "Re: using arrays in my bash script, having problems"
- Next in thread: Icarus Sparry: "Re: using arrays in my bash script, having problems"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 13 Feb 2005 13:28:13 -0800
Thanks Chris, my comments are in line. (I hope this shows up ok)
Which part of the script is giving you trouble?
(the line right about the chmod 777 to make that piece executable. I
cannot execute the constants into my main script. I decided to make
sub-scripts and launch from one main place)
I don't see any bash arrays in your script.
(I moved off of arrays and went to constants)
> ##############################################
> echo "Now I am gathering the Spoof Groups from the master network a
group list"
> ################THIS IS THE NETWORK AND GROUP GREPPER###########
> #First lets do the networks
What are you trying to do to
(this part works fine, it is just the part that starts with MUCH MORE
COMPLICATED that is the issue)
the networks?
> sed 's/$/.*n/g' spoof-groups3 > spoof-groups-with-star-n
Since you are matching the end of the line, there can only be one
substitution per line; you do not need the g flag.
(cool thanks, I will use that)
> grep -f spoof-groups-with-star-n company-network-listing >
network-grep-results
What's the point of this? You don't use network-grep-results
anywhere else in your script.
(it is used above. I just posted the part of the script that is
troublesome)
> #networks are done
> #now we are going to get the groups, this is MUCH MORE COMPLICATED!
What's complicated about it?
(compared to the network portion above it, it is much more involved)
> sed 's/$/.*G/g' spoof-groups3 > spoof-groups-with-star-G
> #grep -f spoof-groups-with-star-G company-group-listing >
group-grep-results
> #we now make the constant template
> echo group1 > constant-template
> echo group2 >> constant-template
> echo group3 >> constant-template
> echo group4 >> constant-template
> echo group5 >> constant-template
> echo group6 >> constant-template
> echo group7 >> constant-template
> #template is now made
Quicker would be:
printf "%s\n" \
group1 group2 group3 group4 group5 group6 group7 > constant-template
And do you really need to do this every time the script is run?
Once the file is created, you can just test for its existence.
(I see your point, but I was trying to make this script movable to any
dir, without copying over multiple files)
> #now we put constant= in front of all our group-with-star-G
> paste constant-template spoof-groups-with-star-G >
spoof-groups-with-constant-command
> #now we replace any spaces with an equal sign
> sed 's/\t/=/g' spoof-groups-with-constant-command >
spoof-groups-with-constant-command-with-equal
> echo Is there an issue?
> #we null out any unused contstants, otherwise the script hangs...
> sed 's/[=\t]$/=nothing/' \
> spoof-groups-with-constant-command-with-equal \
> > spoof-groups-with-constant-command-with-equal-and-nothing
> #now we set our constants in our shell
> chmod 777 ./spoof-groups-with-constant-command-with-equal-and-nothing
> ./spoof-groups-with-constant-command-with-equal-and-nothing
Do you really want everyone to be able to write to the file?
(this is just a beta and I was being lazy, you have a great point from
a security stand point)
> sleep 1
Why?
(just making sure the line above had time to complete)
> grep -A 20 $group1 company-group-listing > group-results1
> echo we DID IT
> The spoof-groups-with-constant-command-with-equal-and-nothing
> looks like this:
> group1=firewall_IntNetAntispoof.*G
> group2=firewall_DMZAntispoof.*G
> group3=firewall_IntNetAntiSpoof.*G
> group4=firewall_G_DMZ.*G
> group5=firewall_MarconiNet.*G
> group6=nothing
> group7=nothing
If your spoof-groups3 file contains:
firewall_IntNetAntispoof
firewall_DMZAntispoof
firewall_IntNetAntiSpoof
firewall_G_DMZ
firewall_MarconiNet
you can generate that with:
awk '{printf "group%d=%s.*G\n", NR, $0}
END { n = NR; while ( n < 7 ) print "group" ++n "=nothing"}
' spoof-groups3
(sweet, I am buying an awk book today! I obviously need it.)
-- I will make the sub-scripts and echo the constants into the sub. Thanks Chris. p.s. This is for a customers firewall so I used a lot of caution when posting. I usually am not so tight-lipped. You probably won't see this kind of partial posting from me again. I see you are a huge contributor to this group and really appreciate the time you took here. Have a good weekend.
- Next message: erik: "grepping for pattern, and then deleting ALL the following lines after the pattern"
- Previous message: Chris F.A. Johnson: "Re: using arrays in my bash script, having problems"
- In reply to: Chris F.A. Johnson: "Re: using arrays in my bash script, having problems"
- Next in thread: Icarus Sparry: "Re: using arrays in my bash script, having problems"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|