|
|
This script is flawed!
But "df -k | awk -F/ '/disk*/ {print $3}'" doesn't list all mounted volumes, not in Lion, anyway. The "df" command apparently always lists results in the same order, so, if the corresponding lists both reflect members which are appropriately filtered, as appears to be the case for the original script, then the items are matched correctly. Also, how could a USB volume be considered anything other than a local volume? If you don't consider it local, how do you define it? Edited on May 08, '12 10:33:44PM by llee
This script is flawed!
Hi llee, This is 'df -k' on my machine: %df -k Filesystem 1024-blocks Used Available Capacity Mounted on /dev/disk0s2 79203656 37059420 41888236 47% / devfs 213 213 0 100% /dev map -hosts 0 0 0 100% /net map auto_home 0 0 0 100% /home /dev/disk2s2 365784156 332133392 33650764 91% /Volumes/LionHD /dev/disk1s1 66559996 65618364 941632 99% /Volumes/NtfsData /dev/disk1s2 36141052 35825216 315836 100% /Volumes/Stuff /dev/disk1s3 53588152 48312924 5275228 91% /Volumes/Spare /dev/disk3s1 256702603 251655315 5047288 99% /Volumes/LX 640GB /dev/disk3s2 306239060 303196948 3042112 100% /Volumes/MacExt //mono@mono-ubuntu/DATA 90905756 88700324 2205432 98% /Volumes/DATA /dev/disk3s3 35929372 34222204 1707168 96% /Volumes/SmallSave //mono@mono-ubuntu/SHARED 30925528 28483832 2441696 93% /Volumes/SHARED //mono@mono-ubuntu/WINSHARE 122047484 119958196 2089288 99% /Volumes/WINSHARE /dev/disk4s2 113970 113970 0 100% /private/tmp/UpdateEngine-mount.gg0KUq6yFM /dev/disk2s3 365949948 333945836 32004112 92% /Volumes/Windows 8 The three volumes with names in all caps are SMB shares mounted by the finder. Now 'df -hlg': %df -hlg Filesystem 1G-blocks Used Available Capacity Mounted on /dev/disk0s2 75 35 39 47% / /dev/disk2s2 348 316 32 91% /Volumes/LionHD /dev/disk1s3 51 46 5 91% /Volumes/Spare /dev/disk3s2 292 289 2 100% /Volumes/MacExt /dev/disk3s3 34 32 1 96% /Volumes/SmallSave /dev/disk4s2 0 0 0 100% /private/tmp/UpdateEngine-mount.gg0KUq6yFMAnd for good measure the output of 'mount': %mount /dev/disk0s2 on / (hfs, local, journaled) devfs on /dev (devfs, local, nobrowse) map -hosts on /net (autofs, nosuid, automounted, nobrowse) map auto_home on /home (autofs, automounted, nobrowse) /dev/disk2s2 on /Volumes/LionHD (hfs, local, journaled) /dev/disk1s1 on /Volumes/NtfsData (ntfs-3g, local, synchronous) /dev/disk1s2 on /Volumes/Stuff (ntfs-3g, local, synchronous) /dev/disk1s3 on /Volumes/Spare (hfs, local, journaled) /dev/disk3s1 on /Volumes/LX 640GB (ntfs-3g , local, nodev, nosuid, synchronous) /dev/disk3s2 on /Volumes/MacExt (hfs, local, nodev, nosuid, journaled, noowners) //mono@mono-ubuntu/DATA on /Volumes/DATA (smbfs, nodev, nosuid, mounted by mono) /dev/disk3s3 on /Volumes/SmallSave (hfs, local, nodev, nosuid, journaled, noowners) //mono@mono-ubuntu/SHARED on /Volumes/SHARED (smbfs, nodev, nosuid, mounted by mono) //mono@mono-ubuntu/WINSHARE on /Volumes/WINSHARE (smbfs, nodev, nosuid, mounted by mono) /dev/disk4s2 on /private/tmp/UpdateEngine-mount.gg0KUq6yFM (hfs, local, nodev, nosuid, read-only, noowners, nobrowse) /dev/disk2s3 on /Volumes/Windows 8 (ntfs-3g, local, synchronous) Hence the problem I mentioned. You have two lists of a different size so when the script is using the position of an item in the first list to index an item in the second list the wrong item is picked up from the list and the wrong drive ends up being unmounted. Just try both ( your version and mine ) and you'll see.As for the second point you mentioned, you are totally right, USB drives are local disks and 'df -l' is of course completely justified in listing them. I was somehow thinking about 'internal drives' when I wrote my post.
This script is flawed!
The only way that I could replicate your results, I guess, would be to try to create mountable volumes with all those disk names. But I did considerable testing on the script I submitted with quite a few different volumes mounted. The list you include first (yours is generated by "df -k") when generated by my script does not include all the volumes that yours includes because it isn't "df -k", it's "df -k | awk -F/ '/disk*/ {print $3}'", and it returns a listing for only the items appearing in your second list. My observation is that because the order of the listed items doesn't change between the filtering of the constructs based on "df -k" and "df -hlg", the script that filters out ineligible members still draws the correct association of items in the two lists. Can you store the output of the two initial commands from my script ("df -k | awk -F/ '/disk*/ {print $3}'", and "df -hlg | awk -F/ '/disk*/ {print $5}'") on your system so they can be compared line for line with the output you already included for "df -hlg"? Edited on May 09, '12 01:30:41PM by llee
This script is flawed!
Hmm, well, could it be as short and sweet as this? Edited on May 09, '12 08:55:12PM by llee
I like it (shorter and simpler)
I tried your shorter version and indeed it works here too. I think the key to this story was to have just one list, the one generated by 'df -l'. Since you asked me (and I know that doesn't really matter anymore),
% df -hlg | awk -F/ '/disk*/ {print $5}'
LionHD
Spare
MacExt
SmallSave
and 'df -k | awk -F/ '/disk*/ {print $3}':
df -k | awk -F/ '/disk*/ {print $3}'
disk0s2 79203656 51490116 27457540 66%
disk2s2 365784156 332114676 33669480 91%
disk1s1 66559996 65618364 941632 99%
disk1s2 36141052 35825216 315836 100%
disk1s3 53588152 48312940 5275212 91%
disk3s1 256702603 251655316 5047286 99%
disk3s2 306239060 303196908 3042152 100%
disk3s3 35929372 34222232 1707140 96%
That's why it didn't work here. As a side note, there's a slight typo in the awk script regex, which should be /disk.*/ and not /disk*/ (luckily it doesn't change anything for the intended purpose). I'm glad you didn't take it the wrong way and that you came up with a really short solution, and I hope I didn't came off as being too pedantic. ;-) |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.41 seconds |
|