4

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
4

When you are printing straight to the terminal, your shell doesn't know about it, so it doesn't know to print its prompt again. You would get similar behavior running e.g. (sleep 1; echo foo) &.

I would suggest either not printing from your udev rule (that seems like the more usual thing to do: be quiet unless something wrong happened), or living with it, knowing that nothing is really broken here; the messages pushed straight to your terminal are parasitic as far as you shell is concerned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.