Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 43

Thread: howto run a script when a USB device is pluged in

  1. #11
    Join Date
    Dec 2007
    Beans
    9

    Re: howto run a script when a USB device is pluged in

    OS : Gusty 7.10 alternate - cli install (command line only)

    Just tried it and confirms it works .

    But a small (can be solved inside launched script) problem exists :

    The script is started several time when device is plugged in ...

    This is the line I use :
    ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="14cd", ATTRS{idProduct}=="6600", RUN+="/home/tux/usb_script_14cdx_6600.ksh"

    I could solve this by working with a tempfile ,and doiing time comparison.
    But this is not a clean solution.
    Better would be if the script was launched only once ...

    Any idea ?

    Greetz ,

    K.

  2. #12
    Join Date
    Oct 2006
    Beans
    149

    Re: howto run a script when a USB device is pluged in

    As a first attempt I would try:
    ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="14cd", ATTRS{idProduct}=="6600", RUN="/home/tux/usb_script_14cdx_6600.ksh"

  3. #13
    Join Date
    Dec 2007
    Beans
    9

    Re: howto run a script when a USB device is pluged in

    Nope ... that doesn't do the trick.

    I'll go for the quick and dirty ...

    I've added this to the launched script ,preventing it to start multiple times within a period of 60 seconds ...

    Maybe a bit of overkill ,but I might use it for more sensible stuff then mounting a disk.

    #!/usr/bin/ksh
    sleep 1
    cat /tmp/epochtimetesfile.txt | head -1 | while read TIMEBEFORE
    do
    #echo "TIME BEFORE IS=$TIMEBEFORE"
    CURRDATE=`(date +'%Y-%m-%d %H:%M:%S UTC')`
    EPOCHTIME=`(date --date="$CURRDATE" +%s)`
    DIFFTIME=`(echo "$EPOCHTIME-$TIMEBEFORE" | bc)`
    #echo "Difftime=$DIFFTIME"
    if [ "$DIFFTIME" -lt "60" ]
    then
    #echo "START AGAIN , DIFF IS TOO SMALL"
    exit
    fi
    done
    #echo "TIME BEFORE IS=$TIMEBEFORE"
    #Current full epoch date/time =
    CURRDATE=`(date +'%Y-%m-%d %H:%M:%S UTC')`
    #echo "$CURRDATE"
    EPOCHTIME=`(date --date="$CURRDATE" +%s)`
    #echo "New epoch time is entered"
    echo "$EPOCHTIME" > /tmp/epochtimetesfile.txt
    #date --date='1970-01-01 00:01:10 UTC' +%s
    #echo "MOUNTING DRIVE"
    wall /home/tux/test.txt


    Thanks for the usefull guide on udev stuff ...

    Kind regards,

    K.

  4. #14
    Join Date
    Dec 2007
    Beans
    1

    Re: howto run a script when a USB device is pluged in

    Hello everybody,

    I would like to RUN an init process from /etc/init.d everytime the USB disk is plugged in.
    I found out that you can't hand over parameters like the "start" or "stop" for the /etc/init.d script.
    Hence, the only way is to set up a one line shell script.



    Best regards,

    Superwallah
    Last edited by Superwallah; January 2nd, 2008 at 01:25 PM.

  5. #15
    Join Date
    Mar 2007
    Location
    Devon UK
    Beans
    1,494
    Distro
    Ubuntu Development Release

    Re: howto run a script when a USB device is pluged in

    Having 3 USB memory sticks and never knowing which is which, I think this thread should be very useful. I'll have a play around and see how I get on. Thanks everyone
    Desktops: AMD64X2 3GB RAM 500GB SATA2 GeForce9400GT - P4 HT 3.2Ghz 1GB RAM 250GB IDE + 2x160GB SATA ATI Radeon X740XL - Laptop AMD AthlonXP 1.6 512MB RAM 120GB HD ATI M200

    Gina's Ubuntu HowTo's for beginners (and reference)

  6. #16
    Join Date
    Nov 2006
    Location
    Winnipeg, Canada
    Beans
    237

    Re: howto run a script when a USB device is pluged in

    I got this running my script (i know it does, echo test >> /home/arron/testfile.txt lets me know).

    I want the script to run a gui program for the logged in user, but it doesn't run. I assumed it was a x screen permission thing, since it runs the script as root, so i tried

    Code:
    su arron -c /bin/mygui
    but still no luck. do i need something else special for it to run? I even tested with gedit with no luck.

  7. #17
    Join Date
    Jun 2008
    Beans
    6

    Question Re: howto run a script when a USB device is pluged in

    Hi,

    This seemed like an appropriate place to post this question...

    I recently bought a netbook with 2 SD cardreaders.
    And I can't get them to work completely automatically.

    I Need to run 2 commands/scripts before they get detected automatically.
    # Jmb38x_d3e.sh (which apparently loads the kernel modules for my card reader)
    # setpci -d 197b:2381 AE=47 (which, I assume makes, sure the SD cards are recognized so they will automount)

    I've put these commands in a little shell script and added it to runlevels 2 trough 5.

    However the setpci command fails during startup and also if I try it manually right after booting.
    It returns the error: "Warning: No devices selected for `AE=47`"

    After inserting an SD card I can run the setpci command without error, and any SD card inserted afterwards automounts.

    I think I need a way to fake an SD card that is inserted during boot, so I can add it to my shell script between de jmb38... and the setpci...
    How would I go about this?

  8. #18

    Re: howto run a script when a USB device is pluged in

    I recently bought a netbook with 2 SD cardreaders.
    And I can't get them to work completely automatically.
    As far as I know all should come with software to autorun...
    What about yours?
    At least there are must be drivers

  9. #19
    Join Date
    Jun 2008
    Beans
    6

    Re: howto run a script when a USB device is pluged in

    I followed this howto.

    here's the specific part:
    Code:
    CARD READER:
    
        *
    
          (NOTE: This section needs to be improved. It seems that card reader is not truly "Fully functional") 
    
    According to DebianAcerOne the following command enables the card reader:
    
    setpci -d 197b:2381 AE=47
    
    The card reader works fine now.
    
        * it might help to suspend/resume
        * a static entry for the device /dev/mmcblk01p in /etc/fstab might help
        * powersaving can be done with the jmb38x_d3e.sh script - 
    
    wget http://petaramesh.org/public/arc/projects/AcerOne_Ubuntu/jmb38x_d3e.sh
    sudo chmod 754 jmb38x_d3e.sh
    sudo mv jmb38x_d3e.sh /usr/local/sbin/
    
    To recognize cards every time.
    
    sudo gedit /usr/local/sbin/jmb38x_d3e.sh
    
    Add the following to line 11
    
    modprobe pciehp pciehp_force=1
    
    After reboot cards are recognized.
    But SD cards would only be recognized when one was inserted @ boot time.

    After a lot of asking around I've gotten at the situation described above...
    Any help is welcome...
    I tough it would be a solvable by echoing something to a device or process but so far, no luck.

  10. #20
    Join Date
    Mar 2006
    Beans
    251

    Re: howto run a script when a USB device is pluged in

    Quote Originally Posted by arron View Post
    I got this running my script (i know it does, echo test >> /home/arron/testfile.txt lets me know).

    I want the script to run a gui program for the logged in user, but it doesn't run. I assumed it was a x screen permission thing, since it runs the script as root, so i tried

    Code:
    su arron -c /bin/mygui
    but still no luck. do i need something else special for it to run? I even tested with gedit with no luck.

    If some one can solve this problem, that would be great for me.

    I have usb sony walkman NW-E00x, to use this usb mp3 player, sony provided a software to load songs into device(we can not just copy and paste the songs), unfortunately that software works only in windows. Luckly some one developed a application in java so that I use that software copied into my usb and use in in my Ubuntu machine.
    http://sourceforge.net/project/showf...roup_id=174319

    So I want that software automatically loaded/open when I plug in the usb. Because it is gui application, I am not succeeded. Same problem like DISPLAY was not configured.

    I tried changing my shell to root account and tried to run that application manually with my user name.

    sudo -u myusername /media/WALKMAN/walkman.sh
    I get those DISPLAY variable errors. Anyone has any workaround?

Page 2 of 5 FirstFirst 1234 ... LastLast

Bookmarks

Posting Permissions

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