Can someone take a look at my scripts what missing, plugin usb drive the script is running can log all my echo but cannot execute command. Is there any configuration in linux or to my scripts need to add?.
What i want to achieve is every time I plugin the usbdisk automatic mount to /media/usb/test
Looking at the output( mount /media/usb/test ), DEVNAME is not set. It looks like the previous fdisk command is not returning anything. What is fdisk -l |grep FAT16 |awk '{print $1}' returning if you run it manually?
If DEVNAME isn't set, the mount command won't know which device to mount, and will look in the fstab / mtab for /media/usb/test to figure out what to do.
Supposedly it will return /dev/sdb1 in my case, already tried manually like this DEVNAME="/dev/sdb1" and put echo $DEVNAME and i see the output, but is not mounting
"Supposedly" doesn't really instil confidence You tried setting DEVNAME manually, and that also didn't work?
Is all of the code in the same script.. e.g. did you export DEVNAME if it's not?
If you set DEVNAME manually, after (or in place of) the fdisk command, there's no reason that the output would be
mount /media/usb/test
instead of
mount /dev/sdb1 /media/usb/test
If the variable DEVNAME is not created as read-only (e.g. gives an error why you try to set it), and the script is not being run in a shell jail (chroot environment), that is.
Generally speaking, to mount a filesystem, you need root privileges. If you're running your script as a non-root user, you can get root privileges for the purpose of mounting the FS, using sudo. If you administer the system you can easily do this by adding something to the "sudoers" file (with the visudo command, not vi), for example, from the sudoers file in CentOS 6:
## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
OK, it's late and I need to go. Let's speed this up.
Are you root? If you are, what error do you get when you try to mount the filesystem manually? A media error, an unsupported type error, an unknown / unsupported FS type error, or what?
Please try to be more forthcoming and communicative with information so we don't end up with a War and Peace-sized thread for what is probably a simple problem.
If you're not root, then the sudo rule you need to add should be for the user you want to allow to be superuser for the purposes of running the command - which won't be root, as root doesn't need sudo to run anything - the su in sudo means super user.. root is already a superuser.
It seems that's not doing what you think it should be. Again, as previously suggested, you should fully qualify the commands (/usr/bin/grep, etc.) - shouldn't make any assumptions about the environment udev is using when it does stuff.
If you change all of the ">> $LOG_FILE" to "&>> $LOG_FILE", you'll also log all the errors, if there are any.
I'll agree with Scott. It looks like something is not being set, or is not mounted to set. Maybe if you post the output of "mount" and "fdisk -l" we can see what's missing.