Following Shell script is for embedded linux if there is no nodes starting with 'sd' in /dev/ directory. In other words, if there is no HDD or other devices mounted on /dev/ directory as /dev/sda1, /dev/sda2 etc, the following script can be used.
If already some nodes are present in /dev/ directory starting with 'sd' like sda1, sda2 etc, previous script (for Desktop linux) )can be used.
while [ 1 ]
do
set ls /dev/sd[a-z][1-9]
if [ -b $1 ]
then
d=$#
else
d=0
fi
while [ 1 ]
do
set /dev/sd[a-z][1-9]
for p in "$@"
do
if [ -b "$p" ]
then
d=`expr "$d" + 1`
echo "$d"
fi
done
if [ "$d" -gt "$#" ]
then
echo Yes..Now Detected.."${@}"
mount=1
break
else
echo not yet
sleep 1
fi
done
sleep 1
echo "It has come $#"
j=0
for p in "$@"
do
arr[$j]=$p
j=`expr $j + 1`
done
echo j="$j"
echo This is the node "${arr[$#-1]}"
mount -t vfat ${arr[$#-1]} /mnt/DEVICE
ls /mnt/DEVICE
node="${arr[$#-1]}"
echo Final node is "$node"
#------------------------------------------#
d1=$j
echo j="$j" "$node"
i=0
while [ 1 ]
do
if [ -b "$node" ]
then
echo "still existing"
else
echo "Disconnected"
umount /mnt/DEVICE/
mount=0
fi
sleep 1
if [ "$mount" -eq 0 ]
then
break
else
continue
fi
done
done
Fine. I think these scripts can be optimized by the shell script experts. I have done this after long time of my Shell script usage. I have used shell script 3 years back in my academic. But because of this shell script, i was able to refresh most of the syntaxes/concepts of shell script. Thats what i needed.
I was very much happy when i completed this.
If anybody done optimization, please mail me the script to pramoda.ma@gmail.com
No comments:
Post a Comment