2 added 17 characters in body
source | link

So I don't know how to use awk very well at all. But I do know that what's going on in the script you linked is a lot of nonsense and that something like the following should work. I'm sorry I can't write this out perfectly well, but since youyou're already calling awk - twice it seems - you should be using something like this.

_chkmem() { return $( 
    free -m | grep "buffers/cache"
        awk '{ 
        percent = ( $3 / ( $3 + $4 ) ) * 100     
        warn = '"${warnlevel?No warning level specified!}"' < percent ? WARNING : OK
        crit = '"${critical?No critical level specified!}"' < percent ? CRITICAL : $warn
        print "Mem $crit : $percent% used"
        if ( $crit != OK ) exit 1
    }')
}

_chkmem || exit 1

So I don't know how to use awk very well at all. But I do know that what's going on in the script you linked is a lot of nonsense and that something like the following should work. I'm sorry I can't write this out perfectly well, but since you already - twice it seems - you should be using something like this.

_chkmem() { return $( 
    free -m | grep "buffers/cache"
        awk '{ 
        percent = ( $3 / ( $3 + $4 ) ) * 100     
        warn = '"${warnlevel?No warning level specified!}"' < percent ? WARNING : OK
        crit = '"${critical?No critical level specified!}"' < percent ? CRITICAL : $warn
        print "Mem $crit : $percent% used"
        if ( $crit != OK ) exit 1
    }')
}

_chkmem || exit 1

So I don't know how to use awk very well at all. But I do know that what's going on in the script you linked is a lot of nonsense and that something like the following should work. I'm sorry I can't write this out perfectly well, but since you're already calling awk - twice it seems - you should be using something like this.

_chkmem() { return $( 
    free -m | grep "buffers/cache"
        awk '{ 
        percent = ( $3 / ( $3 + $4 ) ) * 100     
        warn = '"${warnlevel?No warning level specified!}"' < percent ? WARNING : OK
        crit = '"${critical?No critical level specified!}"' < percent ? CRITICAL : $warn
        print "Mem $crit : $percent% used"
        if ( $crit != OK ) exit 1
    }')
}

_chkmem || exit 1
1
source | link

So I don't know how to use awk very well at all. But I do know that what's going on in the script you linked is a lot of nonsense and that something like the following should work. I'm sorry I can't write this out perfectly well, but since you already - twice it seems - you should be using something like this.

_chkmem() { return $( 
    free -m | grep "buffers/cache"
        awk '{ 
        percent = ( $3 / ( $3 + $4 ) ) * 100     
        warn = '"${warnlevel?No warning level specified!}"' < percent ? WARNING : OK
        crit = '"${critical?No critical level specified!}"' < percent ? CRITICAL : $warn
        print "Mem $crit : $percent% used"
        if ( $crit != OK ) exit 1
    }')
}

_chkmem || exit 1