0

I would like to understand how does a script on a usb stick can lunch itself. I would like to make a script that is on my usb stick and when the usb is connected it lunch a code like this:

#!/usr/bin/env bash

if zenity --question --text="Do you wish to make a backup of your documents/?"; then
    now=$(date)
    cp /my/document/path/* /my/usb/stick/now
fi

The problem is that I don't understand how this .sh file that is on my usb drive know that the usb as been connected and have to lunch itself.

I hope I've explained well enough,

Thanks for your time.

Vincent

  • 1
    Similar [Auto run when USB plugged in](https://stackoverflow.com/q/9454816/3422102) - though that is C++. The issue is the same. Your kernel usb driver (hub) is what detects when a USB device is plugged-in (and then another API (e.g. udev, etc.) generally takes over to configure the permissions for the device for use). An `autorun` framework can be used to look for an `.inf` file on removable devices in order to automatically run the content. See [How to autorun files and scripts in Ubuntu](https://askubuntu.com/q/642511/1423782) Udev can provide the same functionality. – David C. Rankin Dec 08 '22 at 03:39

0 Answers0