I have a bash script which has a line cd /run/media/Username/121C-E137/ this script is triggered as soon as the pen-drive is recognized by the CPU but this line should be executed only after the mounting process is complete. As of now what happens is this line is executed before the pen-drive is mounted and returns an error the directory is invalid.

  • Depends on your system. If you use systemd, you can write a udev rule using SYSTEMD_WANTS... It's documented in man systemd.device. – jasonwryan Apr 23 '14 at 8:14
  • The simplest solution would be to let your script do the mounting. What is causing the mounting now? – Gilles Apr 23 '14 at 21:22

A simple solution would be to have the script periodically check for the directory, and only proceed once it's there:

while [ ! -d "$PENDRIVE" ]; do
    sleep 10

  • 1
    This sleep command is suspending the mounting as well the Pen-drive never gets mounted now until i comment the newly added lines in the script . – Arun Reddy Apr 23 '14 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.