Sponsored Content
Top Forums Shell Programming and Scripting How to use logical operators in multiple if statement Post 302528354 by michaelrozar17 on Tuesday 7th of June 2011 03:52:27 AM
Old 06-07-2011
Place the mail part script in a function and try for checking the conditions..
And if your using double square brackets then use && or || , for single square bracket you can use -a or -o
Code:
 #!/bin/ksh
func_mail()
{
 mailx -s “Status Report” sumone@sumthing.com 
}
 
if [[ "$BatchFrequency" = "Daily" && "$ModuleBusinessName" = "XYZ" && "$Status" = "COMPLETED SUCESSFULLY" || "$Status" = "ABORTED"  ]]
then
        func_mail
elsif [[ "$BatchFrequency" = "Weekly" && "$ModuleBusinessName" = "ABC" && "$Status" = "COMPLETED SUCESSFULLY" ||"$Status" = "ABORTED" ]]
then
       func_mail
elsif [[ "$BatchFrequency" = "Monthly" && "$ModuleBusinessName" = "YUI" && "$Status" = "COMPLETED SUCESSFULLY" ||"$Status" = "ABORTED" ]]
then
       func_mail
else
       echo "Try again"
fi

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

multiple Logical statement

hi I have following if condition line_by_line="0000000000000tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt" if then echo "Exclusion criteria" else echo "Not exclusion criteria" fi above condition works perfectley but if i add one more logical condition... (3 Replies)
Discussion started by: mahabunta
3 Replies

2. Shell Programming and Scripting

Logical AND within a case statement ??

Hi there, probably a really simple question to answer but i cant seem to find it can I use a logical AND (&&) within a CASE statement ie (ps this is useless syntax but youll get the idea case "$var1","$var2" in 'Billy' && 'Bobby') ... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

3. Shell Programming and Scripting

Multiple Logical Operator Issues ...

Hi folks I have a snippet of code Which is like this If ( ( A || B || C ) && D ) then Do some thing.... elif exit fi How to rephrase this and use it so I dont get any Errors ... Looking out for helpful replies .. Thanks & Regards Srikanth GR (1 Reply)
Discussion started by: srikanthgr1
1 Replies

4. Shell Programming and Scripting

And and OR Operators with If Statement.

Hi All, I have 2 variables. Result1 and Result2. I want to put a condition that if Both are True then echo "All True" Else Show Error. Right now i am doing this and getting error. if ; then echo "All True" else echo "Failed" fi; Error. line 8: ' Solution: Looking for (2 Replies)
Discussion started by: mkashif
2 Replies

5. Shell Programming and Scripting

Can you use logical operators in a case statement (bash)?

I'm pretty sure I already know the answer to this, but I want to make sure I'm not overlooking anything. I'm working on a log monitoring script and every 10 lines I want to display a summary of events. The thing is, there are a lot of possible events, that likely won't have happened, so I only want... (0 Replies)
Discussion started by: DeCoTwc
0 Replies

6. UNIX for Dummies Questions & Answers

issue with multiple logical operators

Hi, shell is /bin/ksh I am trying to do the following in my code.. but its showing me an error if ] && ] ]]; then echo "id is $ida and chk_dy is $chk_dy" fi the error I get is syntax error at line 23 : `"$ida"' unexpected I need to execute the... (2 Replies)
Discussion started by: nss280
2 Replies

7. Shell Programming and Scripting

ksh Multiple Pattern Matching Operators

I figured this would be simple, but I am stuck. Variable longpath="/dir1/dir2/dir3/filename.stuff.morestuff.garbage" I want to end up with just "filename.extra.moreextra". So, I want to get rid of the path and .garbage I want to do this with just ksh internals. So, no sed,grep,awk,expr,... (4 Replies)
Discussion started by: Topaz
4 Replies

8. Shell Programming and Scripting

Using Logical Expression in an AWK statement

I'm would to create a script that would give me the results below. Please note the spaces in the log file are actually commas(",".) Log file Data 0:00 21:15 899 43 31 12 25.39 0:00 21:20 736 34 19 15 35.39 0:00 21:20 776 41 28 13 ... (3 Replies)
Discussion started by: ravzter
3 Replies

9. Shell Programming and Scripting

Implementing operators on multiple fields

Hallo Friends, Have a look at my script: awk -F',' '$14==9100' *_201304*.csv|wc -l > pax1; awk -F',' '$14==9101' *_201304*.csv|wc -l >>pax1; awk -F',' '$14==9102' *_201304*.csv|wc -l >>pax1; awk -F',' '$14==9103' *_201304*.csv|wc -l >>pax1 I would like to include field 42. like below ... (9 Replies)
Discussion started by: kekanap
9 Replies

10. UNIX for Beginners Questions & Answers

How to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies
libapache2-mod-perl2-2.0.7::docs::api::APR::Status(3pm) User Contributed Perl Documentationlibapache2-mod-perl2-2.0.7::docs::api::APR::Status(3pm)

NAME
APR::Status - Perl Interface to the APR_STATUS_IS_* macros Synopsis use APR::Status (); eval { $obj->mp_method() }; if ($@ && $ref $@ eq 'APR::Error' && APR::Status::is_EAGAIN($@)) { # APR_STATUS_IS_EAGAIN(s) of apr_errno.h is satisfied } Description An interface to apr_errno.h composite error codes. As discussed in the "APR::Error" manpage, it is possible to handle APR/Apache/mod_perl exceptions in the following way: eval { $obj->mp_method() }; if ($@ && $ref $@ eq 'APR::Error' && $@ == $some_code) warn "handled exception: $@"; } However, in cases where $some_code is an APR::Const constant, there may be more than one condition satisfying the intent of this exception. For this purpose the APR C library provides in apr_errno.h a series of macros, "APR_STATUS_IS_*", which are the recommended way to check for such conditions. For example, the "APR_STATUS_IS_EAGAIN" macro is defined as #define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN || (s) == APR_OS_START_SYSERR + ERROR_NO_DATA || (s) == APR_OS_START_SYSERR + SOCEWOULDBLOCK || (s) == APR_OS_START_SYSERR + ERROR_LOCK_VIOLATION) The purpose of "APR::Status" is to provide functions corresponding to these macros. Functions "is_EACCES" Check if the error is matching "EACCES" and its variants (corresponds to the "APR_STATUS_IS_EACCES" macro). $status = APR::Status::is_EACCES($error_code); arg1: $error_code (integer or "APR::Error object" ) The error code or to check, normally $@ blessed into "APR::Error object". ret: $status ( boolean ) since: 2.0.00 An example of using "is_EACCES" is when reading the contents of a file where access may be forbidden: eval { $obj->slurp_filename(0) }; if ($@) { return Apache2::Const::FORBIDDEN if ref $@ eq 'APR::Error' && APR::Status::is_EACCES($@); die $@; } Due to possible variants in conditions matching "EACCES", the use of this function is recommended for checking error codes against this value, rather than just using "APR::Const::EACCES" directly. "is_EAGAIN" Check if the error is matching "EAGAIN" and its variants (corresponds to the "APR_STATUS_IS_EAGAIN" macro). $status = APR::Status::is_EAGAIN($error_code); arg1: $error_code (integer or "APR::Error object" ) The error code or to check, normally $@ blessed into "APR::Error object". ret: $status ( boolean ) since: 2.0.00 For example, here is how you may want to handle socket read exceptions and do retries: use APR::Status (); # .... my $tries = 0; my $buffer; RETRY: my $rlen = eval { $socket->recv($buffer, SIZE) }; if ($@ && ref($@) && APR::Status::is_EAGAIN($@)) { if ($tries++ < 3) { goto RETRY; } else { # do something else } } else { die "eval block has failed: $@"; } Notice that just checking against "APR::Const::EAGAIN" may work on some Unices, but then it will certainly break on win32. Thefore make sure to use this macro and not "APR::Const::EAGAIN" unless you know what you are doing. "is_ENOENT" Check if the error is matching "ENOENT" and its variants (corresponds to the "APR_STATUS_IS_ENOENT" macro). $status = APR::Status::is_ENOENT($error_code); arg1: $error_code (integer or "APR::Error object" ) The error code or to check, normally $@ blessed into "APR::Error object". ret: $status ( boolean ) since: 2.0.00 An example of using "is_ENOENT" is when reading the contents of a file which may not exist: eval { $obj->slurp_filename(0) }; if ($@) { return Apache2::Const::NOT_FOUND if ref $@ eq 'APR::Error' && APR::Status::is_ENOENT($@); die $@; } Due to possible variants in conditions matching "ENOENT", the use of this function is recommended for checking error codes against this value, rather than just using "APR::Const::ENOENT" directly. "is_EOF" Check if the error is matching "EOF" and its variants (corresponds to the "APR_STATUS_IS_EOF" macro). $status = APR::Status::is_EOF($error_code); arg1: $error_code (integer or "APR::Error object" ) The error code or to check, normally $@ blessed into "APR::Error object". ret: $status ( boolean ) since: 2.0.00 Due to possible variants in conditions matching "EOF", the use of this function is recommended for checking error codes against this value, rather than just using "APR::Const::EOF" directly. "is_ECONNABORTED" Check if the error is matching "ECONNABORTED" and its variants (corresponds to the "APR_STATUS_IS_ECONNABORTED" macro). $status = APR::Status::is_ECONNABORTED($error_code); arg1: $error_code (integer or "APR::Error object" ) The error code or to check, normally $@ blessed into "APR::Error object". ret: $status ( boolean ) since: 2.0.00 Due to possible variants in conditions matching "ECONNABORTED", the use of this function is recommended for checking error codes against this value, rather than just using "APR::Const::ECONNABORTED" directly. "is_ECONNRESET" Check if the error is matching "ECONNRESET" and its variants (corresponds to the "APR_STATUS_IS_ECONNRESET" macro). $status = APR::Status::is_ECONNRESET($error_code); arg1: $error_code (integer or "APR::Error object" ) The error code or to check, normally $@ blessed into "APR::Error object". ret: $status ( boolean ) since: 2.0.00 Due to possible variants in conditions matching "ECONNRESET", the use of this function is recommended for checking error codes against this value, rather than just using "APR::Const::ECONNRESET" directly. "is_TIMEUP" Check if the error is matching "TIMEUP" and its variants (corresponds to the "APR_STATUS_IS_TIMEUP" macro). $status = APR::Status::is_TIMEUP($error_code); arg1: $error_code (integer or "APR::Error object" ) The error code or to check, normally $@ blessed into "APR::Error object". ret: $status ( boolean ) since: 2.0.00 Due to possible variants in conditions matching "TIMEUP", the use of this function is recommended for checking error codes against this value, rather than just using "APR::Const::TIMEUP" directly. See Also mod_perl 2.0 documentation. Copyright mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. Authors The mod_perl development team and numerous contributors. perl v5.14.2 2011-02-08 libapache2-mod-perl2-2.0.7::docs::api::APR::Status(3pm)
All times are GMT -4. The time now is 09:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy