Hi all,
I have a headless home server running Ubuntu Server 11.10 that has been having a little trouble with networking lately. Since the only way to access this server is with SSH, I wanted to make sure there was a way to roll back my changes if the server looses network access. I decided to do this with a udev rule that executes a script when a certain USB drive is plugged in.
My rule (located in /etc/udev/rules.d/100-usb-hotplug.rules) looks like this
Code:
ACTION=="add", ATTRS{idVendor}=="0781", ATTRS{idProduct}=="5150", RUN+="/root/usb_hotplug.sh"
The target script (/root/usb_hotplug.sh) looks like this
Code:
#!/bin/bash
# USB Autorun Script
# Runs when a HOTPLUG is attached and runs the autorun.sh script on that drive.
#Let the user know the script is about to be run
beep -f 1000
#Let the system recognize the drive
sleep 3
#Mount the drive
sudo mount -L HOTPLUG /root/mnt
#Run the script
sh /root/mnt/autorun.sh
#Notify the user with a completion tone
beep -f 1000 -n -f 2000 -n -f 1500
#Unmount the drive
umount /root/mnt
#Make sure udev doesn't run us in an endless loop
#NOTE: We still get stuck in a loop anyway :(
sleep 3
#Bye
exit 0
When the drive is plugged in, the script runs correctly. However, the issue is that the script doesn't stop running. I keep hearing the beeps until I unplug the drive.
Is there a way to stop the script from running in an infinite loop?
Thank you in advanced for your help.
Bookmarks