View Single Post
  #13  
Old 05-11-2007, 04:12 AM
chris_johnsen chris_johnsen is offline
Registered User
 
Join Date: Jan 2007
Posts: 79
concise shell script examples

(The shell script code fragments below are untested since I don't have any AFP volumes, but people developing shell scripts might find the techniques useful.)

Here are some variations that I find a bit more natural for shell scripting:

Code:
mount | awk '/^afp_/ {print $3}' | xargs -n 1 umount -f
The -n 1 might not be needed on the xargs, but it results in the same umount invocations as the previous script (one per volume). Leaving the -n 1 off would put all the volumes into one umount invocation.

Of course, if you really want to always unmount all AFP volumes, something like this might work, too:

Code:
umount -Aft afp
That last variation is probably OK for AFP, but it is inappropriate for NFS since there are several NFS mediated mounts (automount) that are present on most systems (/Network, /Network/Servers, etc.). Changing afp to nfs in that last command would unmount these normal "volumes", too, which probably is not what the user really wants. Something like the first example with an extra pattern in the awk and/or an extra grep before the awk to select just the target volumes would probably be better for NFS volumes.

BTW, head -1 has the same result as sed -n '1p;1q', and is usually much easier to understand for those not versed in sed/ex/vi.
Reply With Quote