- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Merging two condition with && operator is not ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2013 08:11 AM - edited 04-03-2013 08:14 AM
04-03-2013 08:11 AM - edited 04-03-2013 08:14 AM
Hi All,
I am usk ksh shell and trying to code shell script , which would send mail based on som condition. one condition would be something like, if the day is sunday and time is greater then 17:30 then we should able to recieve mail. Also , if the day is not sunday , it continues to check database status and send across the mail , if the database is down. now, when I tried to run the script , it brough following errors on board.
#!/usr/bin/sh
. cpmqa
DATE=`date '+%m%d%y'`
LOG_DIR=/db/cpmqa/users/oracpmqa/monitoring/logs
LOG_FILE=${LOG_DIR}/${DATE}.log
MAIL_LIST="anme@domain.com"
typeset -i mHHMM=`date +%H%M`
typeset -i mDD=$(date +%d)
mDay=`date +%a`
for i in cpmdvfdm cpmqa cpmtest
do
RC=FAILURE
RC=`sqlplus -s <<EOF
oraadmin/cscmon@"$i"
set heading off
set feedback off
set pagesize 0
set trimspool on
select instance_name from v\\$instance;
exit
EOF`
if [[ "${mDay}" = "Wed" && ${mHHMM} -gt 1830 ] || [ "$RC" != "$i" ]] then
echo "Instance $i is down" | mailx -s "ALERT: Instance $i shoud be up `date`" $MAIL_LIST
else
[ "$RC" != "$i" ] then
echo "Instance $i is down" | mailx -s "ALERT: Instance $i is down " $MAIL_LIST
print "`date`: the $i is down " >> $LOG_FILE
echo Failure
fi
done
cpmqa> . test5.sh
ksh: syntax error: `]' unexpected
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2013 10:38 AM - edited 04-03-2013 10:41 AM
04-03-2013 10:38 AM - edited 04-03-2013 10:41 AM
Re: Merging two condition with && operator is not working.
>ksh: syntax error: `]' unexpected
As the message says, you have some bogus "[]" chars in your condition:
if [[ "${mDay}" = "Wed" && ${mHHMM} -gt 1830 ] || [ "$RC" != "$i" ]] then
Remove those "]" and "[" around your "||".
You also need a ";" between the "]]" and the "then":
if [[ "${mDay}" = "Wed" && ${mHHMM} -gt 1830 || "$RC" != "$i" ]]; then
Did you want this to be elif?
else
[ "$RC" != "$i" ] then
I.e.:
elif [ "$RC" != "$i" ]; then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2013 11:28 AM
04-03-2013 11:28 AM
Re: Merging two condition with && operator is not working.
Great !! You really made my day. All working fine now. Well, I am not that good in shell scripting , so used bit of google and bit extracted from old script. I would also appriciate , if you could explain below lines. would like to say thanks once again.
typeset -i mHHMM=`date +%H%M`
typeset -i mDD=$(date +%d)
i know, what below lines suppose to do , but what's a point using curly braces
if [[ "${mDay}" = "Sun" && ${mHHMM} -gt 1730 || "$RC" != "$i" ]]; then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2013 11:47 AM
04-03-2013 11:47 AM
Solution>Great !! You really made my day.
if you are happy with your answers, please click on the Kudos stars of each helpful post.
>if you could explain below lines.
>typeset -i mHHMM=`date +%H%M`
>typeset -i mDD=$(date +%d)
The above lines extract the various time/date components into integer variables. The first one should be converted to use the $() syntax:
typeset -i mHHMM=$(date +%H%M)
A standard caution I learned decades ago. In the above two date(1) commands, what happens if you run it a few microseconds before midnight, so the second one is after? ;-)
>what's a point using curly braces:
if [[ "${mDay}" = "Sun" && ${mHHMM} -gt 1730 || "$RC" != "$i" ]]; then
Just to be pedantic but probably better to use them consistently throughout the whole line and script.
(I usually only use them where I need to do so.)