LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   UDEV: Unable to run a command line interface script after USB automount using udev (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/udev-unable-to-run-a-command-line-interface-script-after-usb-automount-using-udev-895455/)

mohamr2 08-04-2011 01:41 AM

UDEV: Unable to run a command line interface script after USB automount using udev
 
I have the following udev rule (100-USB.rules) placed in /lib/udev/rules.d/ that scans for a USB device and mounts that onto a mount point on detection using a scripts "RunScript.sh" and does unmount on removal of the USB device using another script "ExitScript.sh":

KERNEL=="sd??", SYMLINK+="SWEUpdate"
ACTION=="add", KERNEL=="sd??", RUN+="/usr/local/bin/RunScript.sh"
ACTION=="remove", KERNEL=="sd??", RUN+="/usr/local/bin/ExitScript.sh"

Both the scripts are as mentioned below:
RunScipt.sh:
#!/bin/sh
mkdir /media/USBMount/
mount /dev/SWEUpdate /media/USBMount/

DIR_NAME=/media/USBMount/
xml_name=new.xml
input="$@"

HelpOptions()
{
echo -n "Do you want to proceed with the SWE installation (Y or N | y or n)?"
read input
ParseUserOptions $input
}

ParseUserOptions()
{
if [[ "$input" == "y" || "$input" == "Y" ]];then
echo "Installing the SWE ..."
# call the xml-binary to install the SWE
elif [[ "$input" == "n" || "$input" == "N" ]];then
echo "SWE installation cancelled ..."
else
echo "Invalid User Input!! Please enter a valid option ..."
HelpOptions
fi;
}

#find the XML to be used
xml_filename="`find $DIR_NAME -name "$xml_name" | cut -d "/" -f 4`"

if [ "$xml_filename" == "" ]; then
echo "XML file $xml_filename not found in the USB device ..."
else
echo ""
echo "XML file $xml_filename found in the USB device ..."
echo ""
HelpOptions
fi

ExitScript.sh:
#!/bin/sh
umount /media/USBMount
rmdir /media/USBMount

The RunScript.sh also contains some additional shell command that has to be run after the USB is mounted on the mount point. Whenever I plug-in a USB device, the RunScript.sh is successfully mounting the USB and when plugged out, the ExitScript.sh script is unmounting the device.
But, the issue is that it is unable to run the rest of the shell commands instead they are just ignored.

I have tried monitoring the udev activities with "udevadm monitor", but donot get any useful information. From my investigation, I have understood that the udev is executing its rules in kernel space and is unable to interact with the user space shell to execute the rest of the shell commands.

Kindly help in this regards.

corp769 08-04-2011 06:07 PM

Hello,

This may sound like a dumb question, but when do you plug your device in? Under your GUI window manager, or within an actual terminal screen? You will need actual interaction; You can try running a new instance of xterm, etc, to do this. Or you can think of another way, as there are quite a few ways to do this.

Cheers,

Josh

mohamr2 08-05-2011 08:01 AM

This is on an embedded target with limited functionalities, where I'm trying to introduce a command line interface on a serial port or on a telnet session. I dont have GUI window manager or xterm... I have udev on the target rootfs, which I'm trying to use to achieve this usb automount and running a simple user interaction script.

Please let me know if there are any other methods of achieving this.

catkin 08-05-2011 08:59 AM

Can you post the exact udev rule in CODE tags so we can see where any line breaks are?

What is the output of udevadm info <as required> when the device is plugged in?

mohamr2 08-05-2011 09:30 AM

As mentioned earlier following is the udev rule:

KERNEL=="sd??", SYMLINK+="SWEUpdate"
ACTION=="add", KERNEL=="sd??", RUN+="/usr/local/bin/RunScript.sh"
ACTION=="remove", KERNEL=="sd??", RUN+="/usr/local/bin/ExitScript.sh"

mohamr2 08-12-2011 04:18 AM

the USB device is plugged in at anytime during which the embedded target is operational...

catkin 08-12-2011 10:28 AM

Quote:

Originally Posted by mohamr2 (Post 4434561)
As mentioned earlier following is the udev rule:

KERNEL=="sd??", SYMLINK+="SWEUpdate"
ACTION=="add", KERNEL=="sd??", RUN+="/usr/local/bin/RunScript.sh"
ACTION=="remove", KERNEL=="sd??", RUN+="/usr/local/bin/ExitScript.sh"

Is it all on one line? Posting it in code tags (conveniently available in Advanced Edit mode via the # button) would show clearly.

mohamr2 08-16-2011 08:00 AM

yes true... these lines allow me to mount and unmount the USB automatically on device plug-in. But, it doesnot allow me to run a shell script.

may be udev make it run in a different context... clueless..

catkin 08-16-2011 10:39 AM

Which parts of "Is it all on one line?" do you not understand?


All times are GMT -5. The time now is 05:00 AM.