AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
#Power
 View Only
  • 1.  cannot execute disk space script

    Posted Fri May 06, 2011 11:06 AM

    Originally posted by: rajeshw61


    #!/bin/ksh

    used=0
    mount=${1:-"/mountpoint"}
    threshold=${2:-80}
    #message="hello"
    #SUBJECT="Disk Space Alert"
    #EMAIL="xyz@abcinc.com"
    used=`df -k $mount | grep % | awk '{print $5}' | sed 's/%//g'`

    #echo "Free Space available under \"$mount\" is `expr 100 - $used`%.\n">$message

    if $used -ge $threshold ; # at this point am getting error#
    then
    echo "Space Utilization on \"$mount\" has exceeded the threshhold of ${threshold}%.\n" | mail -s "Disk Space Alert" xyz@abcinc.com

    #/bin/mail -s "$SUBJECT" "$EMAIL" < $message
    fi
    *at if operator it gies "./disk.sh14: 180533: unknown test operator" error

    can any one help guys ,thanks in advance.
    #AIX-Forum


  • 2.  Re: cannot execute disk space script

    Posted Fri May 06, 2011 12:34 PM

    Originally posted by: shargus


    you need square brackets around your test, like this:

    if $used -ge $threshold ;
    then
    echo stuff
    fi

    the open bracket is actually an alias for the test command.
    #AIX-Forum


  • 3.  Re: cannot execute disk space script

    Posted Fri May 06, 2011 12:39 PM

    Originally posted by: shargus


    sorry - I see the square brackets are getting swallowed by the web page...

    Put in an echo $threshold and echo $used just before the if statement. If either one is blank, that's the problem.

    You probably need to check each one for the case where it's blank, such as "if ; " and take appropriate action.
    #AIX-Forum


  • 4.  Re: cannot execute disk space script

    Posted Fri May 06, 2011 12:40 PM

    Originally posted by: shargus


    ok, web page broke my post again...

    
    
    
    if [ 
    "X$user" == 
    "X" ];
    

    #AIX-Forum


  • 5.  Re: cannot execute disk space script

    Posted Tue May 10, 2011 11:03 PM

    Originally posted by: SystemAdmin


    Hi,

    When I tested your script, but with the lines:
    
    print 
    "<$used> <$threshold>" 
    
    if $used -ge $threshold ; # at 
    
    this point am getting error#
    

    the following was displayed:
    
    <Iused 4645> <70>
    

    It would appear the "used" calculation is incorrect.

    Personally, I prefer the double-brackets, for an if expression, since it is far more forgiving with minor errors.

    Regards,
    George
    #AIX-Forum


  • 6.  Re: cannot execute disk space script

    Posted Tue May 10, 2011 11:47 PM

    Originally posted by: SystemAdmin


    Try:
    
    used=`df -k /opt | awk 
    'NR==2{print $5}'`
    

    and
    
    
    
    if [[ $used -ge $threshold ]]; then
    

    #AIX-Forum


  • 7.  Re: cannot execute disk space script

    Posted Thu May 19, 2011 09:22 AM

    Originally posted by: rajeshw61


    am sry for late rply.actuall error was that calluclation before if statement...

    and i was able to resolve it...

    sry again for i cant put full code here as i dont have it here :(
    #AIX-Forum


  • 8.  Re: cannot execute disk space script

    Posted Thu May 19, 2011 09:23 AM

    Originally posted by: rajeshw61


    thanks guys you helpd it happen!! ;)
    #AIX-Forum