IgnorantGuru's Blog

Linux software, news, and tips

devmon 1.0.5

devmon 1.0.5 adds ––exec-on-unmount and ––exec-on-remove options to allow commands to be executed on these events. (Note that exec-on-unmount may not execute for devices mounted before devmon was started, or for devices which were automounted by devmon during startup.)

For example, to have devmon automatically add and remove drives from traydevice you might use:

devmon --exec-on-drive  "traydevice %f" \
       --exec-on-remove "pkill -f \"traydevice %f\""


Another example: to receive notifications using notify-send:

devmon --exec-on-drive   "notify-send -t 3000 \"Device %f %l has been automounted\"" \
       --exec-on-unmount "notify-send -t 3000 \"Device %f %l has been UNmounted\""   \
       --exec-on-remove  "notify-send -t 3000 \"Device %f has been REMOVED\""


Another example: the following user-contributed script can be used to add icons representing mounted and unmounted devices to any desktop. As currently written, this script requires the icon files drive-hdd-unmount.svg and drive-hdd-mount.svg to be placed in ~/.config/devmon/

#!/bin/bash
dev="$1"
devname=`echo $dev | sed 's/.*\///'`  # strip path from device
if [ "$2" = "" ];then
    label="$devname"
else
    label="$2"
fi
state="$3"
desktopbase="${HOME}/Desktop"
desktopentry="$desktopbase/$devname.desktop"
iconbase="${HOME}/.config/devmon"
echo "CreateDeskIcons: dev='$dev' label='$label' state='$state' "

if [ $state = "-1" ]; then
    if [ -e "$desktopentry" ]; then
        rm "$desktopentry" -rf
    fi
    exit
fi

if [ ! -e "$desktopentry" ]; then
    touch "$desktopentry"
fi

echo "[Desktop Entry]"     > "$desktopentry"
echo "Version=1.0"         >> "$desktopentry"
echo "Type=Application"    >> "$desktopentry"
echo "Encoding=UTF-8"      >> "$desktopentry"

case $state in
    "0" ) # not mounted
        icon="drive-hdd-unmount.svg"
        echo "Name=$label"                 >> "$desktopentry"
        echo "Exec=udisks --mount $dev"    >> "$desktopentry"
        echo "Icon=$iconbase/$icon"        >> "$desktopentry"
        ;;

    "1" ) # mounted
        icon="drive-hdd-mount.svg"
        echo "Name=$label"                 >> "$desktopentry"
        echo "Exec=udisks --unmount $dev"  >> "$desktopentry"
        echo "Icon=$iconbase/$icon"        >> "$desktopentry"
        ;;
    * )
        ;;
esac 

Assuming the above script is installed as “createdeskicons”, devmon can run it with:

devmon --exec-on-drive   "createdeskicons %f %l 1" \
       --exec-on-unmount "createdeskicons %f NoLabel -1" \
       --exec-on-remove  "createdeskicons %f NoLabel -1"


Other changes to devmon 1.0.5: When %f is passed to a command, it is no longer single quoted (%d and %l are still single quoted). Also, devmon will now produce a warning on startup if multiple instances are running (which is not recommended for most purposes).

See previous devmon updates

August 3, 2011 - Posted by | Scripts

5 Comments

  1. I tried installing latest devmon on antiX running Debian sid repos, but it wants to install zenity (I use yad) so could you remove zenity from the depends, thanks.

    anticapitalista

    Comment by Anonymous | October 23, 2011

  2. This is my error message when running in chroot (I want to include devmon with antiX):
    dpkg -i devmon_1.0.5-1_all.deb
    Selecting previously unselected package devmon.
    (Reading database … 67523 files and directories currently installed.)
    Unpacking devmon (from devmon_1.0.5-1_all.deb) …
    dpkg: dependency problems prevent configuration of devmon:
    devmon depends on zenity; however:
    Package zenity is not installed.
    dpkg: error processing devmon (–install):
    dependency problems – leaving unconfigured
    Errors were encountered while processing:
    devmon

    However, if installing ‘normally’, no errors (I do not have zenity).
    Any ideas why?

    Thanks

    anticapitalista

    Comment by Anonymous | October 23, 2011

  3. Sorry for the barrage of posts, it seems I do have zenity installed, so my first request still stands ie make zenity a recommends not a depends.

    anticapitalista

    Comment by Anonymous | October 23, 2011

    • Thanks – I will consider that with the next release, and I probably agree with you. I made it a dependency so it gets pulled in automatically.

      In the meantime, keep in mind that devmon is just a single script, so it’s very easy to install without a package. See Script Installation Instructions for details.

      Comment by IgnorantGuru | October 23, 2011

  4. Thanks IgnorantGuru.

    I know it is easy to install without a package, but as antiX is a Debian-based distro it would be nice and cleaner to have it as a deb.

    Once again thanks

    anticapitalista

    Comment by Anonymous | October 23, 2011


Sorry, the comment form is closed at this time.