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


Click here to return to the 'Mount and unmount server shares via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Mount and unmount server shares via AppleScript
Authored by: CkB_Cowboy on Mar 21, '05 03:58:56PM
I've written a simple bash script that outputs a space-delimited list of all IP addresses bound, across all ethernet adapters. You can either call the script by itself to return that list, or pass it an IP address as the sole argument, in which case it returns the IP address if it's bound, or nothing if it isn't.

Check it out:
#!/bin/bash

# echo a list of all bound IPs
#

ISIP_TEMP=`ifconfig -u | grep -w "inet" | awk '{printf " " $2}'`

if [ $1 ]; then
	if [ -n "`echo $ISIP_TEMP | grep -w $1`" ]; then
		echo $1
	fi
else
	echo $ISIP_TEMP
fi

unset ISIP_TEMP

I actually use this script in a handful of other scripts. I hope it's helpful!

- Cowboy

---
My ill-matic homepage:
http://rj3.net/cowboy/

[ Reply to This | # ]

an example:
Authored by: CkB_Cowboy on Mar 21, '05 04:17:02PM
I thought I'd provide an example of usage. I named the script in the parent post isip, put it in the path, and made it executable, so it's accessible to any of my scripts.


#!/bin/bash

if [ `isip 192.168.0.70` ]; then
        open ~/bin/myscript_network_home
else
        open ~/bin/myscript_network_work
fi

Since I've configured my home DHCP server to reserve 192.168.0.70 for my laptop, and that address doesn't fall into the DHCP pool at work, this script can easily tell which network I'm on and run the right app, automagically!

- Cowboy

---
My ill-matic homepage:
http://rj3.net/cowboy/

[ Reply to This | # ]