Error in if statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in if statement
# 8  
Old 09-29-2010
Thanks a lot for all .Its working Fine Now
# 9  
Old 10-18-2010
if statement issue

I am getting below error with extension of above script.


Code:
#!/bin/bash
#set -x
#
grep -  hostawk.log

if [ $? -eq 0 ]; then



              if [ `cat hoststale.log | wc -l` -eq 1 ]; then
              awk '$1 $2 $3 == "---" { exit 1 }' hoststale.log
              #awk '$2 $3 $4 == "---" { exit 1 }' hoststale.log}

                     if [ $? -ne 0 ]; then
                      echo "Found NFS issues on host"
                      u=$(awk '{ print $5 }' hoststale.log)
                      printf "======================================================================================\n"
                      printf "                 NFS issues on host                                                \n"
                      printf "======================================================================================\n"
                      #grep -i $u hostOut.log
                      echo -e "[host@host ]# df -hP | grep -i $u \n"
                      #df -hP | grep -i $u
                      echo " "
                     fi

else
              echo " "
             ## if [ `hoststale.log | wc -l` -gt 1 ]; then
              printf "======================================================================================\n"
              printf "               Found Multiple NFS issues on host                               \n"
              printf "======================================================================================\n"
              echo " "
              printf "======================================================================================\n"
              printf "                 NFS issues on host                                                \n"
              printf "======================================================================================\n"

              for u in `(cat hoststale.log |  awk '{print $5}')`
              do
              #printf "======================================================================================\n"
              #printf "                 NFS issues on host                                                \n"
              #printf "======================================================================================\n"
              #grep -i $u hostOut.log
              #echo -e "[host@host ]# df -hP | grep -i $u \n"
              #printf "======================================================================================\n"
              #printf "                 NFS issues on host                                                \n"
              #printf "======================================================================================\n"
              grep -i $u hostOut.log
              #df -hP | grep -i $u
              echo " "
done


fi
#elif [ -f hostawk.log ]; then
elif [ $#  [ `(cat hostawk.log | grep 1 | egrep -v "G|T|K|M")` ]  -eq 0 ]; then
cat hostawk.log | grep 1 | egrep -v "G|T|K|M"
if [ $? -eq 0 ]; then
     #cat hostawk.log | grep 1 | egrep -v "G|T|K|M" >>hoststale1.log
     #chmod 777 hoststale.log
     awk '$1 $2 $3 == "1" { exit 1 }' hoststale.log
     if [ $? -eq 0 ]; then
     echo "Found NFS issues with 1 on host"
     for u in `(cat hoststale.log |  awk '{print $5}')`
     do
     #grep -i $u hostOut.log  >>/hostfinal.log
     echo $u
     #chmod 777 hostfinal.log
     #mountstale
     done
     fi
fi
else
printf "======================================================================================\n"
printf "                      NO  NFS issues on host                                       \n"
printf "======================================================================================\n"
#echo  `cat  hostOut.log`
echo -e "[host@host ${UUID}]# df -hP \n"
#df -hP
exit
fi


This is the file where its checking
================================

[host@host1 host]# cat hostawk.log
8.9G            2.5G            6.0G            29%             /
28G             25G             3.5G            88%             /dtestx
57G             49G             8.4G            86%             /ttestx
16G             2.4G            13G             16%             /dtesti/out
1               1               1               0%              /ttesti/out
[host@host1 host]#
 

Error I am getting
=================

+ '[' 0 '[' 1 1 1 0% /tbmidi/out ']' -eq 0 ']'
line 55: [: too many arguments


Line number 55
----------------------
 55  elif [ $#  [ `(cat hostawk.log | grep 1 | egrep -v "G|T|K|M")` ]  -eq 0 ]; then


Please help how to check this argument.
# 10  
Old 10-18-2010
Hi, line 55 is just invalid syntax.
# 11  
Old 10-18-2010
Hi
Could you please help me how to correct it.
# 12  
Old 10-18-2010
What are you trying to test?
# 13  
Old 10-18-2010
let me clearly explain you.I am checking for Stale NFS issues on Host.

Code:
This is one example of one host for Stale NFS issue 


type1
==========
[root@host2 host3]# cat host3awk.log
8.9G            6.3G            2.2G            75%             /

79G             5.5G            74G             7%              /txxxxi/mt
-               -               -               -               /txxxxi/out
117G            44G             74G             38%             /txxxxi/app
78G             4.7G            74G             6%              /txxxxi/prod
74G             458M            74G             1%              /txxxxi/in
[root@host2 host3]#

type2
============


[host@host1 host]# cat hostawk.log
8.9G            2.5G            6.0G            29%             /
28G             25G             3.5G            88%             /dtestx
57G             49G             8.4G            86%             /ttestx
16G             2.4G            13G             16%             /dtesti/out
1               1               1               0%              /ttesti/out
[host@host1 host]#
 
Sometimes there are mutiple nfs  issues.

For no NFS issue the output of file is this 
------------------------------------------

[root@host1 host4]# cat host4awk.log
8.9G            2.2G            6.3G            26%             /
29G             9.0G            20G             32%             /taaaa/app
32G             13G             20G             40%             /taaaa/di
[root@host1 host4]#

I have wriiten script to check the NFS issue of this type

Last edited by nareshkumar522; 10-18-2010 at 06:11 AM.. Reason: coding
# 14  
Old 10-18-2010
OK, but what are you trying to test on line 55?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Error code with if statement

hello all im new to unix and when i use below script i get an error : #! /bin/bash Echo -e "enter the name of the file : \c" read file_name if then echo "$file_name found" else echo "$file_name not found" fi running the script i get below error : $ ./hello (26 Replies)
Discussion started by: Ibrahims1
26 Replies

2. Shell Programming and Scripting

Awk/if statement error

Can anybody tell the correct way to use the following awk pattern check within an if statement? When I run this command outside of the if statement cat /tmp/test2.out | awk -v T=$TIME -v G=$GROUP -v C=$CDATE '$0 ~ T && $0 ~ G && $0 ~ C' | grep -i "Starting the group" I get the following... (0 Replies)
Discussion started by: kieranfoley
0 Replies

3. Shell Programming and Scripting

If statement Syntax error

Hi Can you please tell me what is wrong with this line: if && ]; then basically i want to check if x = 12 and F (Filename) end with 'g'. But it is throwing syntax error. (7 Replies)
Discussion started by: rtagarra
7 Replies

4. UNIX for Dummies Questions & Answers

error in if statement

Hi, This is my script to catch any oracle errors. In this, the $sqlerr returns ORA-01017: invalid username/password; logon denied when i specify wrong username/password the if condition is failing. how can i resolve the issue. the if statement gives error sqloutput=`sqlplus -s -L... (1 Reply)
Discussion started by: Swapna173
1 Replies

5. Shell Programming and Scripting

error in insert statement

hi, When i try to run the code below, i get the following error "ksh: syntax error: `(' unexpected" i am not able to figure it out. Can anyone help me? Code: (2 Replies)
Discussion started by: ragavhere
2 Replies

6. Shell Programming and Scripting

Error in IF statement

HI i am getting error while executing the given statement for filename in `cat a/file.lst` do if then echo "Exit Code Description :File $filename - is missing in Input Directory" >a.log exit else count1=`awk 'END {print NR}' $filename` echo "$count1">>a.log count2=`awk 'END {print... (4 Replies)
Discussion started by: ravi214u
4 Replies

7. Linux

error in if statement

Hi , I am getting an error when I run the script for checking word "view" in a file . I am using if statement. like this if then VW_VAR=` cat $TN.${ecmdate}.sql1 | grep -i view | awk '{print $3}' | cut -d '.' -f2 ` echo " VW_$VW_VAR " sed -e... (16 Replies)
Discussion started by: capri_drm
16 Replies

8. Shell Programming and Scripting

Snytax error on If Statement--help

year=`date '+%Y'` month=`date '+%m'` day=`date '+%d'` day=`expr $day - 1` case $month in 1 | 3 | 5 | 7 | 8 | 10 | 12);; if($day =7 ); then $day=6 fi 4 | 6 | 9 | 11);; if ; then $day=31 fi 2);; if ; then if ; then (2 Replies)
Discussion started by: dannyd_y
2 Replies

9. Shell Programming and Scripting

Error with if statement..Please help

:b:hi, I have a script as given below: pr_det="1" if then awk ' BEGIN {printf("%23s","session")}' >> report.txt awk ' BEGIN {printf "\n"} ' >> report.txt else awk ' BEGIN {printf("%55s","file_dsc")} ' >> report.txt awk ' BEGIN {printf("%101s","no_recs")} '... (1 Reply)
Discussion started by: jisha
1 Replies

10. Shell Programming and Scripting

parsing error in if statement

hello, I am trying to parse an error returned by a command inside the if statement but it is just displays the full error instead and then stops. if ; then echo "no such package" else echo "similar version found will use pkgrm" fi the above code just displays please let me know... (2 Replies)
Discussion started by: rakeshou
2 Replies
Login or Register to Ask a Question