I have set a simple udev
rule for my Raspberry Pi (Debian) to automatically mount an USB HDD. It just runs a script which mounts all devices in /etc/fstab
since it's the only one I have and I'm going to have there.
I just need that but I saw that there were some environment variables that got passed to the script and tried to get it to print the label of the drive and the device node name for example just to experiment a bit.
I got it to work, but now when I plug it I get for example:
pi@Gawain ~ $ Disk TOSHIBA_EXT (/dev/sda1) plugged in.Mounting...
And then in the next line I get no prompt, but it's not that the script hasn't exited correctly or anything, it's waiting for input and if I type anything like "pwd
" for example it works, it's just that it shows no prompt.
I'm really not concerned about this since it's just a minor cosmetic thing, and I'll probably leave the script to just mount the drive silently, but I feel curious about why it's behaving that way.
udev rule:
KERNEL=="sd*1", ACTION=="add", RUN+="/home/pi/scripts/mountUSB.sh"
mountUSB.sh:
#!/bin/bash
CONSOLE="/dev/$(who | awk '{print $2}')"
echo "Disk $ID_FS_LABEL ($DEVNAME) plugged in.Mounting..." > $CONSOLE
sudo mount -a