Find the answer to your Linux question:
Results 1 to 3 of 3
hiya folks, can someone shed some light on to why my mount command in the following script doesent seem to get issued? The script is part om my HotPlug susbsystem, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2004
    Posts
    2

    Auto mount script for usb stick - mout command not issued


    hiya folks,
    can someone shed some light on to why my mount command in the following script doesent seem to get issued?

    The script is part om my HotPlug susbsystem, everything works, apart from the mount command it seems.
    I know it goes into the if statement as an echo to file of the $part $MOUNTPOINT variables fired off ok, just prior to the mount command.
    If i take the output from those 2 vars and issue the command from the command line it mounts the usb stick fine.

    cheers
    Andy

    Code:
    #!/bin/bash
    
    MOUNTPOINT=/mnt/usbkey
    IAM=$0
    
    function allAttachedScsiUsb {
    	find /proc/scsi/ -path '/proc/scsi/usb-storage*' -type f 
    }
    function scsiDevFromScsiUsb {
    	echo $1 | awk -F"[-/]" '{ n=$(NF-1); print "/dev/sd" substr("abcdefghijklmnopqrstuvwxyz", n+1, 1) }'
    }
    if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ] 
    then
    	for procEntry in $(allAttachedScsiUsb)
    	do
    		if [ -f /var/run/console.lock ]
    		then
    			CONSOLEOWNER=`cat /var/run/console.lock`
    		elif [ -f /var/lock/console.lock ]
    		then
    			CONSOLEOWNER=`cat /var/lock/cosnole.lock`
    		else
    			CONSOLEOWNER=
    		fi
    		scsiDev=$(scsiDevFromScsiUsb $procEntry)
    		/sbin/fdisk -l $scsiDev >/dev/null
    		if grep -q `basename $scsiDev`1 /proc/partitions 
    		then
    			part="$scsiDev""1"
    		else
    			part=$scsiDev
    		fi
    		if [ ! -z "$CONSOLEOWNER" ]
    		then
    			chown $CONSOLEOWNER:disk $part
    		fi
    		if ! grep -q "^$MOUNTPOINT" /etc/mtab
    		then
    		 	mount $MOUNTPOINT
    		fi
    	done
    	if [ ! -z "$REMOVER" ]
    	then
    		mkdir -p `dirname $REMOVER`
    		ln -s $IAM $REMOVER
    	fi
    elif	[ "${ACTION}" = "remove" ]
    then
    	if grep -q "$MOUNTPOINT" /etc/mtab
    	then
    		umount -l $MOUNTPOINT
    	fi
    fi

  2. #2
    Just Joined!
    Join Date
    Oct 2004
    Posts
    2
    hi all,

    tracked the problem down, to the fact the system is not creating the /dev/sda device until this script is finished or if i wait for it to turn up via a busy loop, it takes 2 mins to appear.

    Can anyone shed any light on why im having this 2 minute delay before the /dev/sda entry gets written.

    if i dont wait for /dev/sda file to turn up, the scripts run through in less than 5 seconds, and i can then issue the mount command manually. This isn't a lot of use for an auto mounting the usb key device!

    cheers
    Andy

  3. #3
    Linux Engineer
    Join Date
    Mar 2005
    Posts
    1,431
    If you use static device nods instead of udev, the entry will always be there, but not always accessible... However, it's a bit weird that it takes so long, on my system itonly takes half a second, some times two.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •