shell script question

Doran L. Barton fozz at iodynamics.com
Wed Oct 12 19:23:58 MDT 2005


Richard K. Miller wrote:
> I'm close to finishing a shell script to automatically enable the DMZ  
> on my Linksys router no matter what IP address my computer has.
> 
> This returns the last octet of my local IP address, which happens to  be 
> a "5":
> ifconfig | grep netmask | grep -v 127.0.0.1 | awk {'print $2'} | sed  
> 's/10.1.1.//'
> 
> This connects to the web interface of my Linksys router to turn on  the 
> DMZ: (notice the "5")
> curl -u admin:password -d  
> "submit_button=DMZ&change_action=&action=Apply&dmz_enable=1&dmz_ipaddr=5 
> " -s http://10.1.1.1/apply.cgi
> 
> How do I connect the two commands?

Piece of cake. Use the backquotes to grab the first command's output:

LAST_OCTET=`ifconfig | grep netmask | grep -v 127.0.0.1 \
     | awk {'print $2'} |sed 's/10.1.1.//'`
curl -u admin:password -d \ 
"submit_button=DMZ&change_action=&action=Apply&dmz_enable=1&dmz_ipaddr=$LAST_OCTET"\ 
-s http://10.1.1.1/apply.cgi

Even so, this seems really hacky (in a bad way). For example, you can pass 
an interface name to ifconfig- call "ifconfig eth0" instead of greping out 
the localhost IP.

-- 
fozz at iodynamics.com is Doran L. Barton, president, Iodynamics LLC
Iodynamics: Linux solutions - Web development - Business connectivity
  "Have a happy new year -- or else you'll be sorry!"
     -- Seen with January on calendar for Japanese trading company



More information about the PLUG mailing list