#!/bin/sh queuedir=/tmp/mountsrv if [ ! -d "$queuedir" ]; then mkdir "$queuedir" fi cd "$queuedir" || exit 1 shopt -s nullglob while true ; do ls -1crt | while read i ; do args="$(cat $i)" name=${args%% *} args="${args#* }" rm -f $i # try to create mount point, allowing up to 10 devices of the same model mntpt= for n in 0 1 2 3 4 5 6 7 8 9 ; do if mkdir "/media/${name}_$n" &> /dev/null ; then mntpt="/media/${name}_$n" break fi done test -n "$mntpt" || continue mount $args $mntpt & disown %1 done if [ -z `ls` ]; then inotifywait -q -q -e CREATE . fi done