I am currently working on a mini project for which I need to set up a udev rule that sends a notification to the desktop when an external storage drive is plugged into the machine.
This notification should contain some basic information of the drive like SN, model, size etc...
I was able get the udev rule to run the script and send the notification to the desktop, but my problem is the notification bubble only appears for 5 seconds and then disappears.
I've tried to set the expiry time in the command, but it still does the same thing . The weird thing is if I run the command in Terminal by itself it's perfectly fine.
Here is my udev rule script
# Mark new block devices as read-only. Only keep the main drive as RW
KERNEL=="sd[c-z]*",ACTION=="add", SUBSYSTEM=="block", KERNEL!="ram*",RUN+="/home/notify-send.sh '%E{DEVNAME}' '%E{ID_MODEL}'"
Here is my notify-send.sh script
export DISPLAY=:0
export XAUTHORITY=/home/akl_dennis/.Xauthority
device_name=$DEVNAME
model_id=$ID_MODEL
icon="/home/READ-WRITE.png"
sn=$(hdparm -I $device_name |awk '/Serial Number:/ { print $3}')
size=$(lsblk $device_name |awk 'FNR ==2 {print $4}')
disk_status=$(blockdev --getro $device_name)
if [ "$disk_status" == 0 ]; then
disk_status="READ-WRITE"
else
disk_status="READ-ONLY"
icon="/home/READ-ONLY.png"
fi
notify-send -i $icon "USB INSERTED" "Device: $device_name\\nSerial Number: $sn\\nModel: $model_id\\nSize: $size\\nStatus: $disk_status"
I noticed that there's some error logs which might relate to the issue, but I'm not sure how to interpret it
org.freedesktop.Notifications[2938]: ** (notify-osd:2942): WARNING **: dnd_is_idle_inhibited(): got error "The name org.gnome.SessionManager was not provided by any .service files"
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME xfce4-session)/environ)"; echo "Setting vars...". And I am using Unity Ubuntu 16.04 – Dennis.Z May 31 '17 at 09:30