Conditional statement with awk

Sometimes bash failed to compare long integer. where awk language can easily compare integer of any range here is the way –

awk ‘BEGIN { if ( ‘$warn’ > ‘$crit’ )
{printf “Unknown.crit must be larger than warn\n”
exit 1}
if ( ‘$used’ < ‘$warn’ )
{printf “OK.Free Space: ‘$free_t’ GB, Space Left ‘$percent’%\n”
exit 2}
if ( ‘$used’ > ‘$warn’ && ‘$used’ < ‘$crit’ )
{printf “Warning. Free Space: ‘$free_t’ GB,Space Left ‘$percent’%\n”
exit 3}
if ( ‘$used’ > ‘$crit’ )
{printf “Critical. Free Space: ‘$free_t’ GB,Space Left ‘$percent’%\n”
exit 4}
}’

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: