If condition getting bypassed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If condition getting bypassed
# 8  
Old 04-18-2005
Use the fact that if "C" is greater than 2 to send your email. I wouldnt try to do it within Awk, though you can using the system () command to send your email via Awk if you choose to do that. Take a look at the Awk Guide on www.gnu.org for details on using system()

Code:
if [ "$c" -gt "2" ]
  then
    echo "Uh Oh. We got a problem"
    mailx -s "Houston We Have A Problem" -r "return-address" email@email.com < log_file
fi

# 9  
Old 04-18-2005
Quote:
Originally Posted by google
Use the fact that if "C" is greater than 2 to send your email. I wouldnt try to do it within Awk, though you can using the system () command to send your email via Awk if you choose to do that. Take a look at the Awk Guide on www.gnu.org for details on using system()

Code:
if [ "$c" -gt "2" ]
  then
    echo "Uh Oh. We got a problem"
    mailx -s "Houston We Have A Problem" -r "return-address" email@email.com < log_file
fi

Hi,
Thanks for the quick reply. I am sorry again bothering you again on this.
I tried the above suggestion. But looks like there is problem the way "if condition is used". I hit an error on if part.

c=`awk -F"," '{ print NF }' $file1`

if [ $c -gt "2" ] ---->I also tried if [ "$c" -gt "2" ]
then
echo "$message3" | /usr/bin/mailx -s "$SUBJECT_EMAIL" $toMail
else
echo "else part"
fi

The error is: Class_Delete_FileCorruption_Check.sh[2]: 2: unknown test operator
else part
Can you please guide me what is going wrong on the "IF" statement.
rkumar28
# 10  
Old 04-18-2005
Make sure that there is exactly 1 space after the first [ and exactly one space before the ].

What is $c being set to when you run that awk statement?

Can you post more of your shell script? Use code tags around the code to preserve formatting. \[code] and \[\/code] (do not include the leading \ characters)
# 11  
Old 04-18-2005
Why not try something like...
Code:
awk 'NF!=2{exit 33}' $file
if [[ $? -eq 33 ]]
then 
    echo "$message" | mailx -s "$subject" $toMail
fi

# 12  
Old 04-19-2005
it seems to me the error here is from the multiple line result of the awk test ... maybe if awk tested for NF per each line this could work ...
Quote:
Originally Posted by rkumar28
Thanks for lot for replying so soon on this.
I changed the awk statement and the "if" statement as suggested:

#c=`awk -F"|" '{ print NF }' test`
c=$(awk -F"|" '{ print NF }' test)

echo "c is $c"

#if [ c > 2 ]

if [ "$c" -gt "2" ]
then
echo "Inside if"
else
echo "else part"
fi

I get the error below:
c is 2
2
2
2
2
[: 2
2
2
2
2: bad number
else part
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

IF [ condition ] help

Hi all Unix newbie - please be gentle Am modifying an existing script to error trap a variable with a length of 0 #!/bin/bash ipfile='/var/data/bin/ipaddress' ] && ipold="$(< "$ipfile" )" ipnew="$( wget -q -O - checkip.dyndns.org | sed -e 's/.*Current IP Address: //;s/<.*$//' )" #... (6 Replies)
Discussion started by: CRChamberlain
6 Replies

2. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

3. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

4. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

5. Shell Programming and Scripting

or in a IF condition

Hi I have to evaluate multiple conditions with an 'or'. Here is an example: if when i use the above i get a error message ' Please help me to know if i am missing something in the syntax. how do i achieve multiple "or" in the same if condition. Thanks. (11 Replies)
Discussion started by: sunrexstar
11 Replies

6. Shell Programming and Scripting

need help in IF condition!!

Hi All ,, This is my code .. i am checcking a file temp66.txt , when i execute this shell it checks whether the file is 0 byte file or not .. if it is a 0 byte file , then Program exists out else it Prints the Echo Statement .. if then RET_CODE=$? if then echo 'File... (18 Replies)
Discussion started by: raghav1982
18 Replies

7. Shell Programming and Scripting

if condition

Hi how to write this: if then usage fi thx (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

8. Shell Programming and Scripting

if condition

Hi friends, :) In a shell script i found the following if condition. echo -n "Which version of $1 do you want to restore ('0' to quit)? : " read desired if ${desired:=1} -ge $index ] ; then echo "$0: Restore canceled by user: index value too big." >&2 exit 1 fi Can... (1 Reply)
Discussion started by: ravi raj kumar
1 Replies

9. UNIX for Dummies Questions & Answers

if condition

suppose a name is read how to check whether the name contains only alphabets and space not non-alphabetic characters and special characters (5 Replies)
Discussion started by: manisha_agrawal
5 Replies
Login or Register to Ask a Question