Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Active connection check in firewall scripts UNIX
Many folks out there have been using ipfw with their OS X machines. Unfortunately, many scripts out there in tutorials will hang if your machine is not connected/dialed into a network.

I've found this issue can be easily solved by adding the following lines at the top of your firewall script (right after the top #! line):
if ! ifconfig -a | grep "status:" | awk '{ print $6 }' | grep "^active" > /dev/null
then
echo "exiting early"
exit
fi
This will run ifconfig and check for active interfaces. Note that all interfaces seem to be up in OS X, whether they are actually connected to a network or not. If it doesn't find any, it will abort the script, thus not hanging forever.

I use my script additions with a script I modified from here.
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[3,118 views]  

Active connection check in firewall scripts | 2 comments | Create New Account
Click here to return to the 'Active connection check in firewall scripts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
can be simplified
Authored by: hayne on Jan 31, '02 09:13:20AM
The first line can be simplified to:
if ! ifconfig -a | grep -q 'status: active'

The -q option to grep makes it run quietly (i.e no output)

If you wanted to make it a bit more robust against possible changes
in the output format of ifconfig, you could use:
if ! ifconfig -a | grep -q 'status:[ \t]*active'

to allow for arbitrary spaces and tabs.

[ Reply to This | # ]
can be simplified
Authored by: Anonymous on Jan 31, '02 07:07:59PM

That was boneheaded on my part. I was trying another way of parsing stuff out, and it didn't work, so I just parsed for active, but it was late and I wasn't thinking :)

Thanks for the correction



[ Reply to This | # ]