yeah, this is good.
Thanks everyone.
Here's what I finally came up with:
safeToDestroy() {
# Paranoid tests before irreversibly writing to device $1
declare -i rval
rval=0
# Don't want to see it listed in $FSTAB:
grep "^[^#]*$1" $FSTAB && rval+=1
# Must not already contain a mounted filesystem:
mount | grep $1 && rval+=2
# Must not already be running as swap:
swapon -s | grep $1 && rval+=4
# Early bailout:
[ $rval ] || return $rval
# It must return file type "data"
[ file -s $1 == "$1: data" ] || rval+=8
# Try to mount it - it must fail
mountPoint=/mnt/random$RANDOM
mkdir $mountPoint
if mount -o ro -t auto $1 $mountPoint; then
rval+=16
umount $mountPoint
fi
rmdir $mountPoint
return $rval
}
Ken Tossell <[EMAIL PROTECTED]> wrote:
> Judah Milgram wrote:
> > Anyone know a fast way to test for presence/type of a file system on a
> > device from within a shell script?
> Perhaps `file -s /dev/hdaX` would work.
>
> [EMAIL PROTECTED]:~# file -s /dev/hda6
> /dev/hda6: Linux rev 1.0 ext3 filesystem data (needs journal recovery)
> [EMAIL PROTECTED]:~# file -s /dev/hda7
> /dev/hda7: x86 boot sector; partition 1: ID=0x96, active, starthead
> 255, startsector 0, 1410096 sectors
>
> (Don't ask; there was much desperation involving oversized livecds.)
>
> You could check a few filesystems of the types you use and find some
> string they share, then match on, e.g., 'filesystem'.
>
> Ken
>