LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices

Reply
 
LinkBack Search this Thread
Old 08-04-2011, 01:41 AM   #1
mohamr2
LQ Newbie
 
Registered: Aug 2011
Location: Bangalore, India
Posts: 5

Rep: Reputation: Disabled
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.
 
Old 08-04-2011, 06:07 PM   #2
corp769
Guru
 
Registered: Apr 2005
Posts: 5,798

Rep: Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978
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
 
Old 08-05-2011, 08:01 AM   #3
mohamr2
LQ Newbie
 
Registered: Aug 2011
Location: Bangalore, India
Posts: 5

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-05-2011, 08:59 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,514
Blog Entries: 27

Rep: Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174
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?
 
Old 08-05-2011, 09:30 AM   #5
mohamr2
LQ Newbie
 
Registered: Aug 2011
Location: Bangalore, India
Posts: 5

Original Poster
Rep: Reputation: Disabled
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"
 
Old 08-12-2011, 04:18 AM   #6
mohamr2
LQ Newbie
 
Registered: Aug 2011
Location: Bangalore, India
Posts: 5

Original Poster
Rep: Reputation: Disabled
the USB device is plugged in at anytime during which the embedded target is operational...
 
Old 08-12-2011, 10:28 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,514
Blog Entries: 27

Rep: Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174
Quote:
Originally Posted by mohamr2 View Post
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.
 
Old 08-16-2011, 08:00 AM   #8
mohamr2
LQ Newbie
 
Registered: Aug 2011
Location: Bangalore, India
Posts: 5

Original Poster
Rep: Reputation: Disabled
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..
 
Old 08-16-2011, 10:39 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,514
Blog Entries: 27

Rep: Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174
Which parts of "Is it all on one line?" do you not understand?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] udev rules - how to pass ATTRS{*} values to the RUN command? catkin Programming 8 09-26-2010 05:43 AM
[SOLVED] Using UDEV to automatically run a script on optical disc mount? atavus Linux - Software 8 03-04-2010 09:48 PM
script command works unless started by udev kscott121 Linux - Software 2 12-31-2007 10:38 PM
Can't run openoffice from bash-script with udev krisealv Programming 1 04-16-2007 11:17 AM
Tricky automount of USB HDU - udev is tough! laan97ac Linux - Hardware 6 12-02-2005 09:29 AM


All times are GMT -5. The time now is 04:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration