11-03-2008
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
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi
I am doing a script like
if
then
echo "table name dosent exist"
exit
fi
the problem is if $table_name is null then i am getting the error
Please help me
Thanks in advance (2 Replies)
Discussion started by: ssuresh1999
2 Replies
2. Shell Programming and Scripting
hi
i am trying to compare a value with value 50. but i am getting
"
I am using
if
then
echo "------------"
fi
please help
thanks in advance
Satya (2 Replies)
Discussion started by: Satyak
2 Replies
3. UNIX for Dummies Questions & Answers
HI,
while running a script, I got the below mentioned error.
/bin/sh: line10 : supportedMozillaVersion() {
case "$*" in
*rv:1.*) return 0;;
*rv:.*) return 0;;
*rv:*) return 1;;
Mozilla\ 1.*) return 0;;
Mozilla\ .*) return 0;;
*) return 1;;
esac
}
supportedFirefoxVersion() {
case... (7 Replies)
Discussion started by: bhag281
7 Replies
4. Shell Programming and Scripting
Im trying to fix my /etc/weekly that rotates various logs however it does them no matter what filesize they are and i want them to only do it if there file size exceeds 2M or something. So I'm playing with a script to get the filesize using a ls -l command which works and puts the value into a... (3 Replies)
Discussion started by: timgolding
3 Replies
5. Shell Programming and Scripting
Im trying to check if a series of directory exists and if not create them, and am having issues. All the instances of test return with the error "test:
#!/bin/bash
location_Parent=~/Documents/sight_of_sound
location_IMG=~/Documents/Sight_of_sound/IMG
location_AUD=~/Documents/Sight_of_sound/AUD... (4 Replies)
Discussion started by: orionrush
4 Replies
6. UNIX for Dummies Questions & Answers
I get the following error
./get_NE05: line 42:
while
do
echo ${STRING_NAME}
J=1
if ; then
EXT=0$I
else
EXT=$I
fi
while
do
echo $I-$J
#calculating last occurrence
OCCURRENCE=`grep -io "${STRING_NAME}"... (3 Replies)
Discussion started by: f_o_555
3 Replies
7. Shell Programming and Scripting
i=0
while
Shell script reports an error "unary operator expected" pointing the above line.
$i by default is 0 and holds integer value and $buf is also holding integer value.
Please can some one let me know what is missing.
Thanks. (1 Reply)
Discussion started by: sunrexstar
1 Replies
8. UNIX for Dummies Questions & Answers
Hiya all,
Why do I get a :unary operator expected when I try to put a condition statement in my shell script (sh) like so and how to fix?
if ; then
echo "say hello"
else
echo "don't say hello"
fi
? It seems if the script receives an argument it works but if I don't put an... (4 Replies)
Discussion started by: cyberfrog
4 Replies
9. UNIX for Dummies Questions & Answers
Hi
I have problem with my script.
I dont now why but i don't change anything and script stop working.
this is my code:
#!/bin/sh
for i in `ps -A | grep pocron.sh | grep -v grep | awk '{print $2}'`
do
COUNT=$((COUNT+1))
done
ostatnie_wykonanie=`cat porader.log`... (1 Reply)
Discussion started by: fotex
1 Replies
10. Shell Programming and Scripting
In all my Googling, this usually happens when someone is comparing a variable, and that variable is unset. That doesn't appear to be the case for me...
#!/bin/bash -x
while read line
do
f=$(echo $line | tr -s ' ' | cut -d' ' -f 3)
echo $f
if
then
echo "This... (2 Replies)
Discussion started by: jnojr
2 Replies