Hi, im in the process of developing an iptables firewall for personal use...Being a newbie in shell scripting im trying to adapt a code i found here:http://homelansecurity.sourceforge.net/script.php. thanks to [J. Howard.] but dont quite understand this block of code below especially the content of '$1' variable as related to the case statement found at the bottom of the script: ie

case '$1' in
'up')
firewall_up
;;.......

##########################
//to show the $1 i dont understand
if [ $EXTINT != "DISABLE" ]; then
EXTIP=$( ifconfig $EXTINT | grep 'inet[^6]' | sed 's/[a-zA-Z:]//g' | awk '{print $1}' )
WANBCAST=$( ifconfig $EXTINT | grep 'inet[^6]' | sed 's/[a-zA-Z:]//g' | awk '{print $2}' )
WANMASK=$( ifconfig $EXTINT | grep 'inet[^6]' | sed 's/[a-zA-Z:]//g' | awk '{print $3}' )
WAN=$EXTIP/$WANMASK
fi

many thanks in advance for any help

$1 is the first command line argument givben when the script is called (i.e. if the command is scriptname hello then $1 is hello).

$1 is the first command line argument givben when the script is called (i.e. if the command is scriptname hello then $1 is hello).

thanks for the post..but i dont quite get it. how do you mean if the 'command is scriptname hello'?what would be the output assigned to EXTIP when ' EXTIP=$( ifconfig $EXTINT | grep 'inet[^6]' | sed 's/[a-zA-Z:]//g' | awk '{print $1}' )' is executed..many thanks

Ps: EXTIP = IP address of eth0 (EXTINT)

I simply used scriptname as a stand in for the name of the script. But lets use a more commonly known script for this, i.e. the inetd script from /etc/init.d

That script you run as /etc/init.d/inetd start to start inetd and as /etc/init.d/inetd start to stop inetd

in the first case $1 is "start" and in the second case $1 is "stop" That is the $1 when used in the case statement. $1, $2, ..... $NF take on a different meaning when used inside awk. An awk command reads input (in this case standard input) line by line and separates the line into "fields" based on consecutive whitespace. i.e. the line "hello world" will result in $1 being hello and $2 being world.

To understand that complete command perform the following steps (eth0 is the most common network interface in linux. If you have something other than linux you will determine for yourself what the interface is. Use ifconfig to find one.)

1) type ifconfig eth0 (this is the first part of the command)

2) then find the first line that starts with inet , but not inet6 (this is the grep part)

3) then remove all alphabetic characters from that line (this is the sed part)

4) Then take the first "word" from that line, i.e. all characters up until the first "whitespace" character, disregarding leading whitespace (this is awk part when $1 is used)
if $2 is used then take the second word, i.e. the first grouping of characters after the first whitespace (disregarding leading whitespace) but before the second whitespace, etc. etc.

I simply used scriptname as a stand in for the name of the script. But lets use a more commonly known script for this, i.e. the inetd script from /etc/init.d

That script you run as /etc/init.d/inetd start to start inetd and as /etc/init.d/inetd start to stop inetd

in the first case $1 is "start" and in the second case $1 is "stop" That is the $1 when used in the case statement. $1, $2, ..... $NF take on a different meaning when used inside awk. An awk command reads input (in this case standard input) line by line and separates the line into "fields" based on consecutive whitespace. i.e. the line "hello world" will result in $1 being hello and $2 being world.

To understand that complete command perform the following steps (eth0 is the most common network interface in linux. If you have something other than linux you will determine for yourself what the interface is. Use ifconfig to find one.)

1) type ifconfig eth0 (this is the first part of the command)

2) then find the first line that starts with inet , but not inet6 (this is the grep part)

3) then remove all alphabetic characters from that line (this is the sed part)

4) Then take the first "word" from that line, i.e. all characters up until the first "whitespace" character, disregarding leading whitespace (this is awk part when $1 is used)
if $2 is used then take the second word, i.e. the first grouping of characters after the first whitespace (disregarding leading whitespace) but before the second whitespace, etc. etc.

Masijade, thank you very much. I absolutely understand it now...much obliged!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.