'AND' boolean not working !!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 'AND' boolean not working !!!!
# 1  
Old 03-17-2013
'AND' boolean not working !!!!

Dear all,
IT seems to be rather small issue, but is not resolved. What Google suggest does no work..!

Code:
#!/bin/bash                                                                                                                                           
date

jobNo=$(awk '/Jobs with Wrapper/ && $NF != 0{s=1}   /List of jobs/ && s{if(p){p=p","$NF}else{p=$NF};s=""}END{print p}' test.log )
jobNo1=$(awk '/List of jobs Cancelled/ && $NF != 0{s=1} s{if(p){p=p","$NF}else{p=$NF};s=""}END{print p}'  test.log)

      #if No JobNo                                                                                                                                    
if [ "$jobNo" = "" ]; then
    echo "Resubmitting" $jobNo1 "=============-----------------------------------------------"
    echo "crab ntuplize_crab -resubmit" $jobNo1 "-c"

      #if No JobNo                                                                                                                                    
elif [ "$jobNo1" = "" ]; then
    echo "Resubmitting" $jobNo "=============-----------------------------------------------"
    echo "crab ntuplize_crab -resubmit" $jobNo "-c"
      #both NULL                                                                                                                                      
elif [ "$jobNo1" = "" -a  "$jobNo2" = "" ]; then
#elif [[ "$jobNo" = "" -a "$jobNo1" = "" ]]; then                                                                                                    
    echo "NO JOBS TO SUBMIT for " $FileNameIndx
    echo "eXiTinG >>"

My isssue is with the RED marked line, I want to test if it is working on the following test.log [1].
But it fail to work. As the test.log satisfy that both job&& job1 are null so it should pass me:
Code:
 
    echo "NO JOBS TO SUBMIT for " $FileNameIndx
    echo "eXiTinG >>"
echo " >>>>>>>>>>>>>>>>>>> Submitted"

But it fail to Work SmilieSmilie !!!!! Please help..

[1]==================
Code:
 
crab:  ExitCodes Summary
 >>>>>>>>> 386 Jobs with Wrapper Exit Code : 0
         List of jobs: 2-6,8-10,12,14-15,17-24,26-28,33-36,38-40,42-46,48,50,52-54,57-71,73-78,80-93,95-102,107,111,115-120,122-127,129-131,136,138,1\
40-156,160,162-163,165,167-173,176-199,201-202,205-206,208-222,224-228,231-244,246-256,259-274,276-277,279,281-282,284,288-291,293-294,297-304,307,30\
9-311,313,315-316,318-332,334,336-339,342-346,348,351-362,364-367,369-372,374-377,380-382,385,387,389-395,398,400-404,407,409,411-414,417-425,431-433\
,435,437-438,441-444,449,451-452,454-485,487-489,491-492,494-496,499-500,502,504-505
     
crab:   505 Total Jobs
 >>>>>>>>> 109 Jobs Running
        List of jobs Running: 7,11,13,16,29-30,32,37,41,47,49,51,55-56,72,79,94,103-106,108-110,112-114,121,128,132-135,139,157-159,164,166,175,200,2\
03-204,207,223,229-230,245,257-258,275,278,280,283,285-286,292,295-296,305-306,308,312,314,335,340-341,347,349-350,363,368,373,378-379,383-384,386,38\
8,396-397,399,405-406,408,410,415-416,426-428,430,434,436,439-440,445-448,450,453,486,490,493,497-498,501,503
 >>>>>>>>> 383 Jobs Retrieved
        List of jobs Retrieved: 2-6,8-10,12,14-15,17-24,26-28,31,33-36,38,40,42-46,48,50,52-54,57-71,73-78,80-93,95-102,107,111,115-120,122-127,129-1\
31,136,138,140-156,160,162-163,165,167-173,176-199,201-202,205-206,208-222,224-228,231-244,246-256,259-274,276-277,279,281-282,284,288-291,293-294,29\
7-300,302-304,307,309-311,313,315-316,318-332,334,336-339,342-346,348,351-362,364-367,369-372,374-377,380-382,385,387,389-395,398,400-404,407,409,411\
-414,417-422,424-425,431-433,435,437,441-444,449,451-452,454-485,487-489,491-492,494-496,499-500,502,504-505
 >>>>>>>>> 5 Jobs Done
        Jobs terminated: retrieve them with: crab -getoutput <List of jobs>
        List of jobs: 25,39,301,423,438

# 2  
Old 03-17-2013
There is no "List of jobs Cancelled" line in your input file, so jobNo1 will be set to an empty string. You never set jobNo2 in this script, so it will also be an empty string. So why do you believe the output is failing? Both "$jobNo1" = "" and "$jobNo2" = "" should be true with the given input.

Note that if you used the commented out elif statement, you would still get the same output; there aren't any "Jobs with Wrapper" lines in your input file with a non-zero Exit Code either. Therefore, jobNo will also be set to an empty string in this script.
# 3  
Old 03-17-2013
Hi Don,
Yeah, I just realized (and figured out one fallacy) that I need to pass it like

Code:
if ["$jobNo" == Null -a "$jobNo1" != Null ]; then
do something with jobNo1

elif ["$jobNo" != Null -a "$jobNo1" == Null ]; then
do something with jobNo

elif ["$jobNo" == Null -a "$jobNo1" == Null ]; then
echo "BOTH NULL, existing "

elif ["$jobNo" != Null -a "$jobNo1" == Null]; then
do something with both $jobNo,$jobNo1

Can you help me in passing these as elif ["$jobNo" != Null -a "$jobNo1" == Null]; ?

Will it work elif ["$jobNo" != "" -a "$jobNo1" == ""]; ??
Also, in the previous script, it was never passing the "do someting" for both
string as NULL command. So I assumed that I did pass them correctly.

Thanks
emily
# 4  
Old 03-17-2013
Quote:
Originally Posted by emily
Hi Don,
Yeah, I just realized (and figured out one fallacy) that I need to pass it like

Code:
if ["$jobNo" == Null -a "$jobNo1" != Null ]; then
do something with jobNo1

elif ["$jobNo" != Null -a "$jobNo1" == Null ]; then
do something with jobNo

elif ["$jobNo" == Null -a "$jobNo1" == Null ]; then
echo "BOTH NULL, existing "

elif ["$jobNo" != Null -a "$jobNo1" == Null]; then
do something with both $jobNo,$jobNo1

Can you help me in passing these as elif ["$jobNo" != Null -a "$jobNo1" == Null]; ?

Will it work elif ["$jobNo" != "" -a "$jobNo1" == ""]; ??
Also, in the previous script, it was never passing the "do someting" for both
string as NULL command. So I assumed that I did pass them correctly.

Thanks
emily
No! No! No! No! No! No! Smilie

First, none of your awk scripts print the string "Null", so comparing the output produced by one of your awk scripts to the string Null is a waste of time; no matter what your input files contain, you already know what the result of the comparison will be.

Second, there has to be a space after the [ and before the ] in:
Code:
if [ expression ]

Third, although some shells may accept it as an extension to the standards, there is no == binary string comparison primitive for the test or [ commands.

And fourth, you don't have a fi to terminate your if statement.

I'm guessing that you want something more like:
Code:
if [ "$jobNo" = "" -a "$jobNo1" != "" ]; then
        printf "Job(s) cancelled: %s\n" "$jobNo1"
elif [ "$jobNo" != "" -a "$jobNo1" = "" ]; then
        printf "Job(s) with non-zero wrapper exit status: %s\n" "$jobNo"
elif [ "$jobNo" = "" -a "$jobNo1" = "" ]; then
        echo "No jobs with non-zero wrapper exit status and no jobs cancelled."
elif [ "$jobNo" != "" -a "$jobNo1" != "" ]; then
        printf "Job(s) with non-zero wrapper exit status: %s\n" "$jobNo"
        printf "Job(s) cancelled: %s\n" "$jobNo1"
fi

or, equivalently:
Code:
if [ -z "$jobNo" -a -n "$jobNo1" ]; then
        printf "Job(s) cancelled: %s\n" "$jobNo1"
elif [ -n "$jobNo" -a -z "$jobNo1" ]; then
        printf "Job(s) with non-zero wrapper exit status: %s\n" "$jobNo"
elif [ -z "$jobNo" -a -n "$jobNo1" ]; then
        echo "No jobs with non-zero wrapper exit status and no jobs cancelled."
else    printf "Job(s) with non-zero wrapper exit status: %s\n" "$jobNo"
        printf "Job(s) cancelled: %s\n" "$jobNo1"
fi

or:
Code:
if [ ! "$jobNo" ] && [ "$jobNo1" ]; then
        printf "Job(s) cancelled: %s\n" "$jobNo1"
elif [ "$jobNo" ] && [ ! "$jobNo1" ]; then
        printf "Job(s) with non-zero wrapper exit status: %s\n" "$jobNo"
elif [ ! "$jobNo" ] && [ ! "$jobNo1" ]; then
        echo "No jobs with non-zero wrapper exit status and no jobs cancelled."
else    printf "Job(s) with non-zero wrapper exit status: %s\n" "$jobNo"
        printf "Job(s) cancelled: %s\n" "$jobNo1"
fi

Obviously you'll want to replace the printf and echo statements with the processing you want to perform, but this gives you three equivalent runnable sequences of commands that will verify that you have correctly adjusted the logic in your if statement tests.
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 03-18-2013
Hi Don
The combinations are working all fine..Smilie

Now, I have to pass the directory name by hand, but rest is all
quite convenient.

Thanks a lot,
emily
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 statement with two boolean conditions

#!/bin/bash if && then echo "True" else echo "False" fi Hi everyone, I am new to UNIX, here I have a if statement elevating two boolean conditions. I thought the output should be True because there are + in the statement. But it turns out to be False. Can anyone... (3 Replies)
Discussion started by: mryuyu1111
3 Replies

2. Shell Programming and Scripting

Boolean expression

hi, im learning python language. and my teacher gives me this question on class: Boolean expression : not (p or not q) what is the correct answer for that? i still dont understand, and please give me a link for a new beginner in python to learn. thanks (1 Reply)
Discussion started by: jazzyzha
1 Replies

3. Shell Programming and Scripting

boolean expression in bash

Can someone, please, help me to make this condition valid/accepted in bash? I really cannot. I'm stuck with the brackets... This one tells me: missing `]' if ]; then # NOTIFY ERROR... fi And... I'd also appreciate a link to bash documents that explain these things. All... (2 Replies)
Discussion started by: mamboknave
2 Replies

4. Homework & Coursework Questions

Boolean expressions for If's

1. The problem statement, all variables and given/known data: Im experimenting with if expressions for an assignment. What i want to do is check if an input of read x y z will be checked against x for 1-999 for y for and for z for 1-999. Am i doing this right? or perhaps you could tell me... (0 Replies)
Discussion started by: Ren_kun
0 Replies

5. UNIX for Advanced & Expert Users

Find Boolean operators help

I was reading this find guide and I saw something with the -and option that I don't think is correct. Do you need the -and option in this? $ find /mp3-collection -name 'Metallica*' -and -size +10000k I found my file that was bigger than 500 MB with and without the -and option. ~ $ find /... (1 Reply)
Discussion started by: cokedude
1 Replies

6. Shell Programming and Scripting

Boolean expression issues

Hi everybody: I'm working on a script to send emails with logs attached based on one single rule..."check if the number of errors has increased since the last time the script ran" Basically what my script does is read from a previous file with the last trace of errors the previous error... (3 Replies)
Discussion started by: hyunkel_01
3 Replies

7. Shell Programming and Scripting

set boolean after comparison

Hi there, Sorry if the title doesn't mean much to you, I don't know how to sum up my pb in one line. I'd like to set a value to 0 or 1 depending on the result of a comparison. Here's what I do: supernova:~# a= supernova:~# isempty=$(] && echo 1 || echo 0) supernova:~# echo $isempty 1... (4 Replies)
Discussion started by: chebarbudo
4 Replies

8. Shell Programming and Scripting

boolean parameter

Hi, I'm calling an oracle procedure from shell script, this procedure has boolean parameter, the default is false, but I need to pass true value to the procedure... how can I do that in shell script , below is my script: ################ Initialise Environment ################# initialise()... (0 Replies)
Discussion started by: aya_r
0 Replies

9. Shell Programming and Scripting

trying to get a boolean response from sed

I have a file coming in with many columns, but the first character of the the coumn is a record type, if I wanted to get a true/false kind of response as to whether it contains at least one of each type of record how would be best? sed -e '/01/!d; /02/!d; /03/!d; /04/!d' datafile returns... (4 Replies)
Discussion started by: badg3r
4 Replies
Login or Register to Ask a Question