bash - Script not working when evoked by udev rule -


i linux mint user , trying write rule, execute script when plug in usb. #!/bin/sh script, not succeed access usb (even normal cd) while if run same script command line, works perfectly.

the rule created purpose is:

action=="add", subsystem=="usb", attr{idvendor}=="058f", attr{idproduct}=="6387", run+=="/home/dario/bin/backup_usb" 

where backup_usb instance looks like:

#!/bin/sh sleep 10 cd /media/dario/  echo " in: $(pwd)" >> /home/dario/bin/log.log cd /media/dario/dario_usb/  # that's device plugged in. echo " in: $(pwd)" >> /home/dario/bin/log.log 

the output is:

i in: /media/dario/  , in: / 

while expecting:

i in: /media/dario/  , in: /media/dario/dario_usb/ 

i grateful help.

(this edited version of question)

first, rule wrong. consider like:

action=="add", subsystem=="usb", attr{idvendor}=="058f", attr{idproduct}=="6387", run+="/home/dario/bin/backup_usb" 

second: kill sleep 10. if udev running scripts in order , waiting each finish before running next, can potentially block subsequent script (such 1 doing mount), preventing happening @ all. we're going differently, putting polling in background:

#!/bin/bash #      ^^^^ - has bash, c-style loop syntax used below bashism #             ...as [[ ]] construct.  exec </dev/null >/home/dario/usb.log 2>&1 set -x cd /media/dario || exit (   ((retries=0; retries<10; retries++));     [[ -d dario_usb ]] && grep -q -e dario_usb /proc/mounts && continue     sleep 1 # retry   done   cd dario_usb || exit   echo "success" ) & 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -