0

I am looking for an update mechanism. How can I detect on linux that a generic usb stick has been plugged in and check if there is special file on it (e.g. control_update.txt)? If this file is detected, a script should be executed to just copy the binary and library file and the other files (html, php, js, ...) from the USB Stick to the Linux system, using a bash script.

I found this question and answer: Bash script to detect when my USB is plugged in and to then sync it with a Directory. Does this mean that by using these commands I will have access to usb, and It will directly execute a script, so the only thing I need is to write the script to execute?

I suppose this will be the way to search for a file, and cat would be used to copy update files..

if [ -f print_control.txt ]; then
  echo "File found!"
  cp
fi
Community
  • 1
  • 1
commandos2389
  • 175
  • 1
  • 10
  • Many systems will automount the filesystem on your USB device to a path like `/media/yourvolumelabel`. Therefore if it is always the same stick, it could be sufficient to check using `[ -f /media/yourvolumelabel/print_control.txt ]`. The `cp` command is used for copying files, type `man cp` for more information. – Michael Jaros Sep 11 '15 at 08:35
  • @mario2389 there is no difference between writing commands in a bash terminal or in a bash script. `cat` is not used to copy files. You have an awful lot of questions here, maybe you should spend a bit of time learning how the shell works before attempting this problem. – arco444 Sep 11 '15 at 08:49
  • If you want to actually *react* to plugging in the stick, the information in your link (using udev) is the way to go.. but if you want to check if it is there at the time the script is running (and something else should start your script), there are various other ways. I have outlined the simplest which will not work on all systems, but it does not depend on any extra tools. `cat` is used to concatenate files and then print their content. You would not use it to copy files. Shells running scripts can use the same commands as interactive shells. – Michael Jaros Sep 11 '15 at 08:50
  • @Michael Jaros Yes, I think this link provides me information I need. May you help me writing this script, at least in pseudo language? – commandos2389 Sep 11 '15 at 09:01
  • @arco444 I am totally wrong, I know that terminal is bash terminal, and with bash scripts I can execute almost any command I am using in terminal. I know i have to learn many things before I can write this, but I want to try "learning by doing" anyway. – commandos2389 Sep 11 '15 at 09:01
  • @Michael Jaros Am I right that when I use commands from link above, that I will have access to usb, and I dont need path for update file in my script ? – commandos2389 Sep 11 '15 at 09:10

0 Answers0