igor012 |
08-02-2012 11:48 AM |
script root notify-send for current X11 user.
Hello,
I created a script that checks the quotas of the disk and display a notification when the quota is reached. It works well.
I want to have this script executed by the root user.
here is the script
Code:
TIMEOUT="12000"
ICON_WARN="/usr/share/pixmaps/warning.png"
ICON_INFO="/usr/share/pixmaps/info.png"
XUSR=$(w | grep -w :0 | awk '{ print $1 }') #get the current X11 user
#test if the current is root or empty and stops if so.
if [ -z $XUSR ] ; then
exit 0
elif [ $XUSR = "root" ] ; then
exit 0
fi
getquota () {
quota -s -w -u $XUSR | grep homeserv | sed -r 's/ +/ /g'| cut -d " " -f "$1" | \
sed -r 's/M/ /g' | sed -r 's/\*//g'
}
#GET HOME SIZE
HME=$(getquota 2)
# #GET SOFTWARE LIMIT
SLIMIT=$(getquota 3)
# #GET HARDWARE LIMIT
HLIMIT=$(getquota 4)
#TEST
#Test if the limit is reached or not
if [ ${HME} -eq ${HLIMIT} ]; then
DISPLAY=:0.0 /usr/bin/notify-send "WARNING ! ${XUSR} Your HOME directory is full."\
"It has reached the hardware limit (${HLIMIT}MB). Please clean up now ! "\
-i ${ICON_WARN} -t ${TIMEOUT}
elif [ ${HME} -ge ${SLIMIT} ]; then
DISPLAY=:0.0 /usr/bin/notify-send "WARNING ! ${XUSR} Your HOME directory is almost full: ${HME}MB"\
"It has reached the software limit (${SLIMIT}MB). Please clean up !"\
-i ${ICON_WARN} -t ${TIMEOUT}
-i ${ICON_INFO} -t ${TIMEOUT}
fi
Where is the problem ?
Thank you
|