Prompt Detail:
To create a script that auto runs every time a new network is detected in Linux, you can use a combination of udev rules and a shell script.
- Create a new udev rule:javascript
sudo nano /etc/udev/rules.d/99-new-network.rules
- Add the following line to the rule:
This will trigger the scriptmakefileACTION=="add", SUBSYSTEM=="net", RUN+="/path/to/your/script.sh"
/path/to/your/script.sh
every time a new network device is added to the system. - Save and close the file.
- Create a new shell script:bash
sudo nano /path/to/your/script.sh
- Add your script commands to the file. For example, you might want to configure the new network device, or start a network service.
- Save and close the file.
- Make the script executable:bash
sudo chmod +x /path/to/your/script.sh
- Reload the udev rules:css
sudo udevadm control --reload-rules
Now, every time a new network device is detected on the system, the udev rule will trigger the execution of your shell script, allowing you to perform any necessary configuration or setup.
Add a comment