#!/bin/sh
# Script for mounting all devices, formated with UFS, EXT4, FAT, FAT32 or NTFS.
clear
substring1=da
substring2=wd
substring3=p
substring4=s
# unmount all
cd /dev
# analyze character-files in /dev
for i in $( ls ); do
# seeking if the character-file in /dev is a mountable disk
if [ "$i" != "${i%$substring1*}" ] || [ "$i" != "${i%$substring2*}" ] ; then
# seeking if the character-file in /dev has partition
if [ "$i" != "${i%$substring3*}" ] || [ "$i" != "${i%$substring4*}" ] ; then
echo "Substring IS in $i"
# unmout the device if conditions above are ok
umount /dev/$i
fi
fi
done
#read some
clear
# remove all directories used by previous mount
if [ -d "/media/disk" ]; then
rmdir /media/disk/*
else
mkdir /media/disk
fi
echo "removed dir"
#read some
clear
cd /dev
# mount all
# analyze character-files in /dev
for i in $( ls ); do
# seeking if the character-file in /dev is a mountable disk
if [ "$i" != "${i%$substring1*}" ] || [ "$i" != "${i%$substring2*}" ] ; then
# seeking if the character-file in /dev has partition
if [ "$i" != "${i%$substring3*}" ] || [ "$i" != "${i%$substring4*}" ] ; then
echo "Substring IS in $i"
# Create directory for the finded device
mkdir /media/disk/$i
# trying to mount msdos
mount_msdosfs /dev/$i /media/disk/$i
clear
# trying to mount ext4
ext4fuse /dev/$i /media/disk/$i
clear
# trying to mount ntfs
ntfs-3g /dev/$i /media/disk/$i
clear
mount /dev/$i /media/disk/$i
fi
fi
done
echo "done"
# read some
clear
mount
if already mounted) ! mount /dev/ad0 /media/disk0
and the device is mounted ok => no output message.if "there is a message from mount" then
if "there is a message from extafuse" then
if "there is a message from msdosfs" then
if "there is a message from ntfs-3g" then
"device is not mountable"
You don't seem to have any formatting in your script.
The output of mount with no parameters can be checked to see if a particular path is mounted.
Spaces and tabs are free, please indent to indicate control flow.
mount
in a script ( for analyze it ).Most commands have a return code you can use to check if the command succeeded or not. It's a special variable you can check in scripts.Hum, in a script, how to catch the output of a command ?
Because it you domount /dev/ad0 /media/disk0
and the device is mounted ok => no output message.
mount /dev/ad0 /media/disk0
if [ $? -eq 0 ]; then
echo "Success!"
else
echo "Something went wrong!"
fi
$? Expands to the exit status of the most recent pipeline.
Code:mount /dev/ad0 /media/disk0 if [ $? -eq 0 ]; then echo "Success!" else echo "Something went wrong!" fi
#!/bin/sh
mounted=`/sbin/mount`
echo $mounted
echo $mounted
= "Lot of blabla" => It works ;-)#!/bin/sh
mounted=`/sbin/mount /dummy/dev /dummy/mnt`
echo $mounted
echo $mounted
= "" => nothing ;-(...
By the way... =>
=>Code:#!/bin/sh mounted=`/sbin/mount` echo $mounted
echo $mounted
= "Lot of blabla" => It works ;-)
The output ofBut this =>
=>Code:#!/bin/sh mounted=`/sbin/mount /dummy/dev /dummy/mnt` echo $mounted
echo $mounted
= "" => nothing ;-(
Fre;D
/sbin/mount /dummy/dev /dummy/mnt
would be empty on stdout(4) for the variable. It would all show to stderr(4). if [ $? -eq 0 ]; then
) is working like charm => exactly what I want => many, many thanks. mv /media/disk/da0 /media/disk/ntfs_da0
but without luck...