2007/12/01

find the mdns name for an IP addr

This seemed like it might be useful and then after I dug through to finally solve the problem, it may be for only a very limited set of circumstances. :)

And interesting script anyway: Given an IP address, find the mdns (AKA ZeroConf or Bonjour; formerly Rendezvous) name - which might help give you a better idea who's there):

#!/bin/bash

# use mdns (local subnet only) to show machine name for a given host IP addr
# (ex: for machines w/ DHCP addrs and therefore unintersting domain names)

if [ -z "$1" ] ; then echo "must supply a host as 1st/only arg"; exit; fi

if [ -n "$2" ] ; then echo "must supply only one arg"; exit; fi

# is it necessary to ping it first, to make sure it's in the ARP table?
#if ! $(ping -c1 "$1") ; then echo "error pinging host"; exit; fi

if ! arpOutput=$(arp "$1") ; then echo "error in arp host"; exit; fi

arpMAC=$(echo "$arpOutput" | sed 's/.*\([a-zA-Z0-9]\{1,2\}:[a-zA-Z0-9]\{1,2\}:[a-zA-Z0-9]\{1,2\}:[a-zA-Z0-9]\{1,2\}:[a-zA-Z0-9]\{1,2
\}:[a-zA-Z0-9]\{1,2\}\).*/\1/g')
arpMAC=$(echo "$arpMAC" | sed 's/^\(.\):/0\1:/' | sed 's/:\(.\):/:0\1:/g' | sed 's/:\(.\):/:0\1:/g')

echo "starting mdns browse; you'll have to hit ^C to get control back..."

dns-sd -B _workstation._tcp | grep "$arpMAC"

# end

Script to notify if any outdated MacPorts

Updated version here.

-----

Add the script below as a cron job and it'll notify* you if you have any outdated MacPorts.

*Presuming you're configured to have cron job output emailed to you, it'll notify by email. If you have growl installed, it growl at you too. Lastly, it logs to /var/log (which probably requires creating that log file first).

(Updated for recent tweaks.)

#!/bin/bash

# 20071110 mvgfr: check for outdated macports & notify if any - via growl & stdout (emailed when cron'd)
# 20080209 mvgfr: must run sync before, so it can learn about updates!
# also added "-H localhost" workaround for growl Leopard bug (ignores some)

# may take awhile; is this an issue?
/opt/local/bin/port sync

potentialOutput=`/opt/local/bin/port outdated`

if [ "$potentialOutput" != "No installed ports are outdated." ] ; then
echo "$potentialOutput"
if [ -f /usr/local/bin/growlnotify ]; then
/usr/local/bin/growlnotify -H localhost -s -m "macports: $potentialOutput"
fi
fi

echo "`date "+%Y%m%d-%H%M%S"`: $potentialOutput" >> /var/log/port-outdated.log

#end

timestamp bash history entries

Wow; bash3 has a terrific feature; the shell variable HISTTIMEFORMAT will timestamp entries in your history - so you can get a *much* better idea of what happened, especially since it's so easy to have multiple sessions going at the same time, so that commands in the history get somewhat interleaved.

Add
HISTTIMEFORMAT='%Y%m%d-%H%M%S: '

to (for example) your .bash_profile.

And Leopard (MOSX 10.5) has bash3 by default; nice.

MOSX: My $PS1

PS1='\[\e]0;\u@\h\a\]\D{%Y%m%d-%H%M%S} \u@\h \W [\j]\n$ '

This sets the Terminal title bar to:
user@node - current-command

Which is dynamic; it changes as you issue commands. (Slick.)

And it sets the prompt to:
date-time user@node working-dir [jobs]
$

It's an awfully long prompt, so it wraps, and puts the familiar "$" at the start of the *second* line.

Why? It's sometimes *very* handy to have the prompt indicate when that command was issued.

(BTW: Bracketing the window title bar potion in "\[" and "\]" is critical; otherwise (since it doesn't print those char in the prompt itself) readline will miscalculate where you are on the line and things get ugly.)

Show ALL recently-modified prefs

Search 'full-path' for plist (pref) files that were modified more recently than 'ttt' (ex: '5 minutes ago') and dump them in human-readable format:
find 'full-path' -iname '*.plist' -newermt 'ttt' -print | xargs -n1 | sed 's/.plist$//' | xargs -n1 defaults read
(Note: It is important to specify a *full* path.)

Issue a sequence of commands, and walk away

You're ssh'd into a server and need to issue a sequence of commands that'll take awhile - and your connection might drop, terminating those commands. Try this:
nohup bash -c "cmd1; cmd2; cmd3" &

Which starts the sequence and sends it immediately to the background (the trailing ampersand) - and also sets it so that even if the controlling terminal goes away, it continues to run (via "nohup"). If you really do need to kill it, use the -KILL signal.

Caveats: Watch your stdin/stdout/etc - this is generally most useful for commands that require no input and generate no output, since, for example, you just disconnected stdin and stdout by sending it to the background.

The above is handy to know if you need to sudo the commands - since you will: a) not see the "Password:" prompt, and b) not be able to respond to it. Here's the cheat: As long as you're in a default ssh config, there's a timeout; sudo commands issued within the timeout don't prompt. So if you need to sudo the above, issue an innocuous "sudo ls" (or some such) just before, to authenticate and get the timer running.

To find out what background jobs there are:
jobs -l

Which also shows the process ID, so you can watch it via top or some such.

Want a little more feedback? How about:
nohup time bash -c "date; cmd1; cmd2; cmd3" &

Which will display the date the inner commands started and then some stats about the time the other commands took, after they're all done.

Need to make sure they each work, before going to the next? Try this:
nohup bash -c "cmd1 && cmd2 && cmd3" &

The double ampersand tells bash to execute following commands ONLY if the previous one succeeded. (More specifically, if it's exit code was zero.)

And you can get more fancy by putting some "echo" commands in there, piping the output to mail, etc.

Validate/verify MD5 or SHA1 hashes

Want to confirm that download hasn't been altered?

MD5:
if [ $(md5 -q pathHere) == 'md5-hash' ] ; then echo "OK"; else echo 'md5 hash mismatch!'; fi

SHA1:
if [ $(/usr/bin/openssl sha1 pathHere | awk '{print $NF}') == 'sha1-hash' ] ; then echo "OK"; else echo 'sha1 hash mismatch!'; fi


Substitute the path of the file to validate for "pathHere" above; similarly, the published hash for "md5-hash" or "sha1-hash".

Sure you could wrap it in a script, by why bother, when you have QuickSilver?

MOSX: Open a subfolder on a share, whether the share is already mounted or not

Mac OS X's "open" shell command is powerful - though strangely dependent on the mount state of shares.

Executing
open afp://server.example.com/share/top-folder/sub1/sub2

Will open the share - and, if the share was already mounted, ignore the rest of the path.

So, here's a quick command (make sure it's all one one line) that will open the subfolder, whether the share is already mounted or not:
if [ -d /Volumes/share ]; then open /Volumes/share/top-folder/sub1/sub2 ; else open afp://server.example.com/share/top-folder/sub1/sub2 ; fi

Adaptation for other protocols (ex: SMB), other mountpoints and error-checking are left as an exercise for the reader. :)

Help! (PX502 and Retrospect)

I've got a Quantum PX502 tape library on Fibre Channel that I'm *attempting* to use with the EMC (formerly Dantz) Retrospect backup application (running under Mac OS X Server 10.4.10) - and it's giving me fits!

It won't complete a backup; each time, Retrospect loses contact with the PX502 before it completes; usually *well* before it completes. At this stage, it's usually an error 205 (from Retrospect) and "Bad reply received" from the PX502.

Quantum has sent NCR techs out to work on it, though it's actually gotten worse since they started. :/

EMC says the detailed SCSI log shows activity they're not familiar with - and they *just* got a PX502 to test (!) -- even though the EMC compatibility DB specifically shows this config as supported. (Quantum's DB also shows this is a supported config.)

Is there *anyone* out there using a PX502 with Retrospect? I'd appreciate *any* feedback at all!

Kerio, Palm, VersaMail & ActiveSync

Interesting mix of several technologies that looks pretty useful.

Had some trouble putting all the pieces together, so here are some clues for anyone else in a similar boat:

  • Check the Kerio config; what ports is it using? Are the services you want (ex: https) on?
  • Triple-check the firewall config. (It's the *really* silly things that get you...)
  • Yes, you probably do need the magical EAS SP2 update though check the Palm Support site for some model/service -specific info first.
  • VersaMail apparently allows only a single account to be configured for ActiveSync; the choice simply does not appear if another account is already using it.
  • If you're using a self-signed cert, there are some pitfalls; see info in links below.
  • If you're using a wildcard, it likely will not work. If you're a DigiCert customer, they've got you covered: They issue a credit to your account to cover a single domain name cert which will be fine. And if you need to change the server name, they've got a handy (and fast) "Reissue" button for you. Well done, folks!
  • And the key my boss found: Specify the server address (in VersaMail) via IP address instead of domain name; strange.


Some other refs that may be helpful: