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


Click here to return to the '10.5: Mount a partition or volume on demand' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Mount a partition or volume on demand
Authored by: Ram-Z on Aug 12, '09 02:09:59PM
So this is what i got:

dev_id=`diskutil list | awk '/\\yPARTION_NAME\\y/{ match( $0, /disk[0-9]+(s[0-9]+)?/ ); print substr( $0, RSTART, RLENGTH); }'` && echo $dev_id
It does the trick nicely for me. I just added a word boundary around the partition name e.g. \y...\y

I don't have any partition with spaces but it might work as well.

[ Reply to This | # ]
10.5: Mount a partition or volume on demand
Authored by: Ram-Z on Aug 12, '09 02:14:23PM
The && echo... is of course not necessary... I was just using for tests purposes.
The bash script would look like this:

#! /bin/bash
dev_id=`diskutil list | awk '/\\yPARTION_NAME\\y/{ match( $0, /disk[0-9]+(s[0-9]+)?/ ); print substr( $0, RSTART, RLENGTH); }'`
[[ $dev_id ]] && diskutil mount $dev_id


[ Reply to This | # ]
10.5: Mount a partition or volume on demand
Authored by: tedw on Aug 12, '09 02:47:54PM
So this is what i got: dev_id=`diskutil list | awk '/\yPARTION_NAME\y/{ match( $0, /disk[0-9]+(s[0-9]+)?/ ); print substr( $0, RSTART, RLENGTH); }'` && echo $dev_id It does the trick nicely for me. I just added a word boundary around the partition name e.g. y...y I don't have any partition with spaces but it might work as well.
I puddled with it a bit and decided to drop awk altogether - ended up with this:
dev_id=`diskutil list | egrep '.{33}PARTION_NAME {2,}' | egrep -o 'disk[0-9]+(s[0-9]+)?'`
the first grep returns a line where the partition name is in the name column and has at least two spaces following; the second grep digs out the actual device name from that line. not very elegant, though...

is there a way to tell awk to use fixed width fields rather than delimiters? apparently there is supposed to be a FIELDWIDTHS variable that can be set, but I can't seem to get it to work in Darwin.

[ Reply to This | # ]