Re: using arrays in my bash script, having problems

From: erik (ewitkop90_at_hotmail.com)
Date: 02/13/05


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.


Relevant Pages

  • Re: [SLE] PCMCIA Billington eth-pcmcia
    ... IINM the problem is caused by the fact that the network gets started before ... echo "This card uses the 8139too module, ... echo "Restart pcmcia subsystem" ... And make the script run late in the whole process by linking to the script ...
    (SuSE)
  • Shell script termination with exit function in backquotes
    ... When I run the following script, I would expect to see no output: ... echo -n 'before' ... echo line 3: `exit 1` ... called before any of the echo lines are allowed to execute. ...
    (freebsd-questions)
  • Re: to add username & password into my login.cmd - login script
    ... echo You are now logged into %computername% ... echo Now setting up your computer for network access. ... The above is a logon script that we r using in our network. ... When we run this script it keeps asking for username & password. ...
    (microsoft.public.windows.server.scripting)
  • What development rpm am I missing?
    ... I am trying to execute a simple script that includes: ... echo 'Is this correct: ... I would like to add as little as needed, as this is suppose to be a production system, but then again simple script elements like this SHOULD work. ...
    (Fedora)
  • interactive script called suring startup on Fedora Core 2
    ... Because I have four possible work locations, I have four network ... configurations that I choose from using an interactive bash script, ... configuration to use when I boot. ... it pauses but doesn't echo the menu to ...
    (comp.os.linux.misc)