LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to run a script inside a flash after mounting it (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-run-a-script-inside-a-flash-after-mounting-it-902603/)

mindgames 09-12-2011 10:45 AM

how to run a script inside a flash after mounting it
 
hello!!!!

I wish to run a script from a flash drive, I need to execute the script that is in the flash after mounting it, no matter in what computer I connect it. So how the script could "know" that the flash is mounted on and execute itself afterwards???

David the H. 09-12-2011 12:05 PM

Programs can't execute themselves. It would have to be invoked by some autorun feature set up on the target system. Fortunately there's no autorun system I know of that would work on every system. The last thing I want is my system executing random programs anytime someone sticks something into it.

The automount functions on some linux systems also disable execute ability on removable drives by default, particularly on fat/ntfs drives. You often need to reconfigure the mount command to give it exec permission before you can run programs. This may require root permission.

Now it should be possible to set something up on systems under your control so that it executes that script when that stick is mounted. Some automount systems have the option of executing arbitrary programs during mounting, I believe. halevt is one possibility that comes to mind, for example. But there's a lot of variability in how distros do their automounting, so I can't give you anything more specific.

mindgames 09-12-2011 12:46 PM

thank you very much, I was thinking in a very innocent script, i realized that it would be a real disaster if we get that kind of permission in every system. I going to transform my idea. thanks again!!!

David the H. 09-13-2011 10:23 AM

Yes, your script may be innocent, but that doesn't mean they all are.

Back when I was a Windows user, one of the first things I did on my systems was to disable the CD autorun feature. It's just like Microsoft to add something like that.

Of course, that hasn't stopped people from developing similar programs for Linux too:

http://linux.die.net/man/1/autorun

Even then, notice how you have to configure your fstab to allow exec permission first.

And what do you know, look at what else I found when I was searching for the above page:

http://www.net-security.org/secworld.php?id=10544


All times are GMT -5. The time now is 02:33 AM.