Last active
February 11, 2016 12:04
-
-
Save tong/6278125 to your computer and use it in GitHub Desktop.
Autoexecute scripts on external drives on mount
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOST=$(cat /etc/hostname) | |
SCRIPTFILE="autoexe_$HOST.sh" | |
MOUNTDELAY=3 | |
if [ -z "$1" ]; then | |
MOUNTDIR=/media | |
else | |
MOUNTDIR=$1 | |
fi | |
echo "Watching for disks $MOUNTDIR" | |
inotifywait -me create --format %w%f $MOUNTDIR | while read DISKPATH | |
do | |
SCRIPT="$DISKPATH/$SCRIPTFILE" | |
sleep $MOUNTDELAY | |
if [ $? -eq 0 ]; then | |
zenity --display=:0.0 --question --text="Execute $SCRIPT ?" | |
if [ $? -eq 0 ]; then | |
RESULT=$(/bin/bash "$SCRIPT") | |
RESULT="$RESULT\n\n---\nEject drive?" | |
zenity --display=:0.0 --question --title="$SCRIPT Result and Question" --text="$RESULT" | |
if [ $? -eq 0 ]; then | |
umount "$DISKPATH" | |
fi | |
fi | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment