Results 1 to 4 of 4

Thread: integer expression expected (with crontab)

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Question integer expression expected (with crontab)

    Hi all,
    i'm a newby in shell script. I have hier a script this will not work with crontab (integer expression expected)
    The problem is the Integer comparison "-gt". Whit console the script works fine.

    Any idea ?

    thanks for any help.

    Stefan

    Code:
    sensor_cleandisk() 
    {
        # grab input variables with sane defaulting
        LOG_DIR=${1:-}
        UTC=${2:N}
        WARN_DISK_USAGE=${3:-1}
        CRIT_DISK_USAGE=${4:-2}
    
        [ ! -d "$LOG_DIR" ] && return 1    
    
        CUR_USAGE=$(df -P $LOG_DIR | grep -v -i Dateisystem | awk '{print $5}' | tr -d %)
      
        # let's change colour based on severity
        if [ "$CUR_USAGE" -gt "$CRIT_DISK_USAGE" ]; then
            USE_COL=${RED}
        elif [ "$CUR_USAGE" -gt "$WARN_DISK_USAGE" ]; then
            USE_COL=${YELLOW}
        else
            USE_COL=${GREEN}
        fi
    
        echo_msg 1 "disk space currently at ${USE_COL}${CUR_USAGE}%"
        
        if [ "$CUR_USAGE" -gt "$CRIT_DISK_USAGE" ]
        then
            # grab time in GMT
            if [ "$UTC" == "Y" ]
            then
                TODAY=$(date -u "+%Y-%m-%d")
            else
                TODAY=$(date "+%Y-%m-%d")
            fi
            cd "$LOG_DIR/dailylogs"
    
            # find the oldest directory and exclude today
            OLDEST_DIR=$(ls | sort | grep -v $TODAY | head -n 1)
            if [ -z "$OLDEST_DIR" -o "$OLDEST_DIR" == ".." -o "$OLDEST_DIR" == "." ]
            then
                echo_msg 1 "${RED}no old log(s) available to clean up"
            else
                cd "$OLDEST_DIR"
                OLDEST_FILE=$(ls -t | tail -n 1)
            
                if [ -n "$OLDEST_FILE" ]
                then
                    echo_msg 1 "removing file: $OLDEST_DIR/$OLDEST_FILE"
                    rm -f $OLDEST_FILE
    
                    if [ -z "$(ls -t | tail -n 1)" ]
                    then
                        cd ..
                        echo_msg 1 "removing empty dir: $OLDEST_DIR"
                        rmdir "$OLDEST_DIR"
                    fi
                else
                    cd ..
                    echo_msg 1 "removing empty dir: $OLDEST_DIR"
                    rmdir $OLDEST_DIR
                fi
              
                # run cleandisk again as rm'ing one file might been enough
                # but we wait 3 secs and hope any open writes are done.
                sync
                sleep 3
                sensor_cleandisk $LOG_DIR $UTC $WARN_DISK_USAGE $CRIT_DISK_USAGE
            fi
    
        # simple warning (no action taken) of increased disk usage
        elif [ "$CUR_USAGE" -gt "$WARN_DISK_USAGE" ]
        then
            echo_warning_msg 1 "disk space is approaching critical levels"
        fi
    }
    Last edited by StefanS; 27th April 2012 at 06:02 PM.

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    445
    Thanks
    0
    Thanked 61 Times in 57 Posts
    Rep Power
    9

    Default

    hi,

    what's curUsage value?
    Code:
    df -P /var  | grep -v -i Dateisystem | awk '{print $5}' | tr -d '%'
    Capacity
    24
    better:
    Code:
    df -P /var | awk 'NR > 1 && ! /[Dd]atesystem/{sub("%","",$5); print $5}'
    24
    PS: by convention, uppercase variable names are for environmental variables only.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Hi, Watael,
    can you show my your examble in my script ?

    thx
    Stefan

  4. #4
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    485
    Thanks
    10
    Thanked 49 Times in 46 Posts
    Rep Power
    8

    Default

    Hi,
    Please try with following
    PHP Code:
    sensor_cleandisk() 
    {
        
    # grab input variables with sane defaulting
        
    LOG_DIR=${1:-}
        
    UTC=${2:N}
        
    WARN_DISK_USAGE=${3:-1}
        
    CRIT_DISK_USAGE=${4:-2}

        [ ! -
    "$LOG_DIR] && return 1    

        
    # CUR_USAGE=$(df -P $LOG_DIR | grep -v -i Dateisystem | awk '{print $5}' | tr -d %;)
        
    CUR_USAGE=$(df -P $LOG_DIR grep -vE "^Dateisystem|tmpfs|cdrom" awk '{print $5}' tr -%;)
      
        
    # let's change colour based on severity
        
    if [ "$CUR_USAGE-gt "$CRIT_DISK_USAGE]; then
            USE_COL
    =${RED}
        
    elif "$CUR_USAGE-gt "$WARN_DISK_USAGE]; then
            USE_COL
    =${YELLOW}
        else
            
    USE_COL=${GREEN}
        
    fi

        echo_msg 1 
    "disk space currently at ${USE_COL}${CUR_USAGE}%"
        
        
    if [ "$CUR_USAGE-gt "$CRIT_DISK_USAGE]
        
    then
            
    # grab time in GMT
            
    if [ "$UTC== "Y" ]
            
    then
                TODAY
    =$(date -"+%Y-%m-%d")
            else
                
    TODAY=$(date "+%Y-%m-%d")
            
    fi
            cd 
    "$LOG_DIR/dailylogs"

            
    # find the oldest directory and exclude today
            
    OLDEST_DIR=$(ls sort grep -v $TODAY head -n 1)
            if [ -
    "$OLDEST_DIR-"$OLDEST_DIR== ".." -"$OLDEST_DIR== "." ]
            
    then
                echo_msg 1 
    "${RED}no old log(s) available to clean up"
            
    else
                
    cd "$OLDEST_DIR"
                
    OLDEST_FILE=$(ls -tail -n 1)
            
                if [ -
    "$OLDEST_FILE]
                
    then
                    echo_msg 1 
    "removing file: $OLDEST_DIR/$OLDEST_FILE"
                    
    rm -f $OLDEST_FILE

                    
    if [ -"$(ls -t | tail -n 1)" ]
                    
    then
                        cd 
    ..
                        
    echo_msg 1 "removing empty dir: $OLDEST_DIR"
                        
    rmdir "$OLDEST_DIR"
                    
    fi
                
    else
                    
    cd ..
                    
    echo_msg 1 "removing empty dir: $OLDEST_DIR"
                    
    rmdir $OLDEST_DIR
                fi
              
                
    # run cleandisk again as rm'ing one file might been enough
                # but we wait 3 secs and hope any open writes are done.
                
    sync
                sleep 3
                sensor_cleandisk $LOG_DIR $UTC $WARN_DISK_USAGE $CRIT_DISK_USAGE
            fi

        
    # simple warning (no action taken) of increased disk usage
        
    elif "$CUR_USAGE-gt "$WARN_DISK_USAGE]
        
    then
            echo_warning_msg 1 
    "disk space is approaching critical levels"
        
    fi

    Rahul Patil <http://www.linuxian.com>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. integer expression expected (with crontab)
    By goncalod in forum Shell scripting
    Replies: 2
    Last Post: 8th November 2011, 07:50 PM
  2. [Solved] Script help [: =: unary operator expected
    By redtred in forum Shell scripting
    Replies: 2
    Last Post: 25th July 2011, 08:31 AM
  3. [Solved] unary operator expected-How to solve this error?
    By aish in forum Shell scripting
    Replies: 2
    Last Post: 20th April 2011, 09:59 AM
  4. Diff b/w /etc/crontab and /usr/bin/crontab
    By Prachi in forum Shell scripting
    Replies: 6
    Last Post: 4th February 2009, 08:29 AM
  5. Replies: 3
    Last Post: 22nd February 2007, 02:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •