The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unary operator expected error ssuresh1999 UNIX for Dummies Questions & Answers 2 10-28-2008 09:33 PM
"test: argument expected" error mvalonso UNIX for Dummies Questions & Answers 7 10-17-2008 12:16 PM
missing binary operator before token "(" mannam srinivas Linux 4 08-07-2008 07:43 AM
Argument ${1} returning "dev" [newbie inside] felipebb Shell Programming and Scripting 1 06-09-2008 04:03 PM
Returning a "0" if folder is empty Raynon Shell Programming and Scripting 12 06-01-2007 06:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-03-2008
theamrit theamrit is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 2
Question awk returning "[: ==: unary operator expected"

Hi All,

I am new to shell scripting and right now I am just limited to using the pre-written scripts. I am in to Infrastructure management where we use different scripts to get the information passed on to the monitoring tools. I am trying to use this script to get the information about the process consuming most CPU and it works for me in RHEL 5 machine but when I run on Solaris 10 box, I am getting the following error:

awk: syntax error near line 1
awk: illegal statement near line 1
./check_top_process.sh: line 39: [: ==: unary operator expected

The script is as follows:

#! /bin/sh
#
# Bill Beavis
#
# todo: better checking for commandline arguments
CLIMIT=80
WLIMIT=50
STATE_OK=0
STATE_CRITICAL=2
STATE_WARNING=1
print_help() {
echo ""
echo "Usage: check_top_process -w <warning> -c <critical>"
echo ""
echo "This plugin checks the top running process."
echo ""
exit 0
}
case "$1" in
-w)
WLIMIT=$2
CLIMIT=$4
;;
-c)
CLIMIT=$2
WLIMIT=$4
;;
--help)
print_help
exit $STATE_OK
;;
-h)
print_help
exit $STATE_OK
;;
*)
esac
if [ `echo $WLIMIT $CLIMIT |awk '{print ($1 > $2) ? "true" : "false" }'` = "true" ]
then
echo "Error: WARNING value must be below CRITICAL value"
print_help
exit $STATE_OK
fi


x=`UNIX95= ps -eo pcpu,comm,user,pid,time |sort -rnk1 | head -1`
y=`echo $x |awk '{print $1 "% command=" $2 " user=" $3 " pid=" $4 " cputime=" $5}'`
if [ `echo $x $CLIMIT |awk '{print ($1 > $6) ? "true" : "false" }'` = "true" ]
then
echo $y
exit $STATE_CRITICAL
fi

if [ `echo $x $WLIMIT |awk '{print ($1 > $6) ? "true" : "false" }'` = "true" ]
then
echo $y
exit $STATE_WARNING
fi

echo $y
exit $STATE_OK

I know that I am missing on something but am unable to find the exact issue. The script is giving errors on the lines highlighted in RED color.

Please help .....

Thanks in advance for your help.....

Amrit
  #2 (permalink)  
Old 11-03-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,309
Try /usr/xpg4/bin/awk:

Code:
/usr/xpg4/bin/awk '{print ($1 > $2) ? "true" : "false" }'
instead of:
Code:
awk '{print ($1 > $2) ? "true" : "false" }'
  #3 (permalink)  
Old 11-03-2008
theamrit theamrit is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 2
Hi Franklin,

Thanks a lot for your response. I changed it and the script is working perfect.

You were really of great help...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0