LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-02-2012, 11:48 AM   #1
igor012
Member
 
Registered: Feb 2010
Posts: 89

Rep: Reputation: 2
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
 
Old 08-02-2012, 12:37 PM   #2
YankeePride13
Member
 
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262

Rep: Reputation: 55
Quote:
Originally Posted by igor012 View Post
Hello,
Code:
#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
Not 100% sure what the question means, but here you have it set to exit when you are root. Also, if you are logging in as a non-root user and then 'sudo -s'ing or 'su -'ing, the return value of w will be the user you had logged in as, not root.
 
Old 08-03-2012, 03:19 AM   #3
igor012
Member
 
Registered: Feb 2010
Posts: 89

Original Poster
Rep: Reputation: 2
Hello,
I didn't explain enough. This script is not correctly executed as root user.
Code:
#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
Just checks if the current x11 user is root or not.
 
Old 08-03-2012, 04:25 AM   #4
igor012
Member
 
Registered: Feb 2010
Posts: 89

Original Poster
Rep: Reputation: 2
I also added a file creation in the test to make sure it's been executed. I ran it under root and it worked but no sign of a notification.
Code:
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}
        echo "1" >> /datas/overH
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}
        echo "1" >> /datas/overS
else
        DISPLAY=:0.0 /usr/bin/notify-send "INFO ! ${XUSR} Your home directory: ${HME}MB"\
        -i ${ICON_INFO} -t ${TIMEOUT}
        echo "1" >> /datas/good
fi
So it seems related to the display.

Last edited by igor012; 08-03-2012 at 04:26 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] notify-send not work as CGI script? djstava Linux - Desktop 2 05-30-2010 11:10 PM
Small bash script to notify server user makowka Linux - Server 2 02-15-2010 02:17 AM
using notify-send ashikahamed Ubuntu 0 05-02-2008 06:09 AM
Notify user of event through enlightenment/X11 Quantum0726 Linux - Software 5 07-25-2005 09:28 PM
Why does X11 work for ROOT user only? webvandals Linux - Software 2 03-12-2004 11:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration