程序超简单,以前没写过这方面的,算是边学边做吧。
busybox的sh和bash有些不兼容,做了一些fix才使它work fine。
#!/bin/sh
#create by
#mail: jinglexy at yahoo.com.cn
#2009-04-15
while true
do
# --------------------------------------
#echo "loop -=----------------------------"
rm -f /var/vision.mount.tmp
touch /var/vision.mount.tmp
mount | while read MOUNT_ENT ;
do
DEV_FIND=""
echo $DEV_FIND > /var/vision.mount.tmp
DEV_NAME=""
MNT_NAME=""
if echo $MOUNT_ENT | grep "/dev/sd" > /dev/null; then
DEV_NAME=`echo "$MOUNT_ENT" | awk -F " " '{print $1}'`
MNT_NAME=`echo "$MOUNT_ENT" | awk -F " " '{print $3}'`
#echo "mount entry: $DEV_NAME, $MNT_NAME"
fdisk -l 2<&- | while read DISC_ENT ;
do
if echo $DISC_ENT | grep $DEV_NAME > /dev/null; then
DEV_FIND="we are find"
echo $DEV_FIND > /var/vision.mount.tmp
#echo "111111111111111111111111, $DEV_FIND"
fi
done
read DEV_FIND < /var/vision.mount.tmp
if [ "$DEV_FIND" = "" ]; then
echo "#####dev poll out? $DEV_NAME, $MNT_NAME"
rm -f /var/vision.mount.size
umount "$MNT_NAME"
fi
fi
done
rm -f /var/vision.mount.tmp
touch /var/vision.mount.tmp
fdisk -l 2<&- | while read DISC ; # list all files in directory
do
DEV_FIND=""
echo $DEV_FIND > /var/vision.mount.tmp
DEV_NAME=""
MNT_NAME=""
if echo $DISC | grep "FAT32" > /dev/null; then
DEV_FIND="TRUE"
echo $DEV_FIND > /var/vision.mount.tmp
fi
if echo $DISC | grep "NTFS" > /dev/null; then
DEV_FIND="TRUE"
echo $DEV_FIND > /var/vision.mount.tmp
fi
if echo $DISC | grep "Linux" > /dev/null; then
DEV_FIND="TRUE"
echo $DEV_FIND > /var/vision.mount.tmp
fi
read DEV_FIND < /var/vision.mount.tmp
if [ "$DEV_FIND" = "TRUE" ]; then
DEV_NAME=`echo "$DISC" | awk -F " " '{print $1}'`
MNT_NAME=`echo "$DEV_NAME" | awk -F "/" '{print $3}'`
MNT_NAME="/var/mount/$MNT_NAME"
if [ ! -d "$MNT_NAME" ]; then
mkdir -p "$MNT_NAME"
fi
if mount| grep "$DEV_NAME" > /dev/null; then
echo "already mount: dev_name: $DEV_NAME, mnt_name: $MNT_NAME" > /dev/null
else
echo "not mount: dev_name: $DEV_NAME, mnt_name: $MNT_NAME" > /dev/null
mount -t auto "$DEV_NAME" "$MNT_NAME"
#echo "mount finish"
df "$DEV_NAME" 2>&1 > /dev/null
#echo "df finish"
fi
fi
done
sleep 1
done
#if [ "$1" = "daemon" ]; then
# #sleep 1
# $0 daemon &
#fi
阅读(2200) | 评论(0) | 转发(0) |