Echo command not working in the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Echo command not working in the script
# 1  
Old 07-07-2017
Echo command not working in the script

HI
I have and echo command which works perfectly in the shell but when i execute in the script it gives me an error code

query is as below

Code:
QUERY=`echo  "Select Severity,Dupl_count,Creation_Time,Last_Received,Node_Name,Node_Name,Object,Message_Group,Message_Text,Last_Annotation from " \
                " (  SELECT " \
                "      decode(msg.severity,1,'Unknown',2,'Normal',4,'Warning',8,'Critical',16,'Minor',32,'Major') as Severity " \
                "       , msg.dupl_count    as Dupl_count " \
                "       , TO_CHAR(msg.local_creation_time,'DD-Mon-YYYY HH24:MI:SS') as Creation_Time " \
                "       , TO_CHAR(msg.local_last_time_received,'DD-Mon-YYYY HH24:MI:SS') as Last_Received " \
                "       , node.node_name    as Node_Name " \
                "       , msg.application   as Application " \
                "       , msg.object        as Object " \
                "       , msg.message_group as Message_Group " \
                "       , msgt.text_part    as Message_Text " \
                "       , ann.anno_text     as Last_Annotation " \
                "      FROM     opc_hist_messages msg " \
                "       , opc_hist_msg_text msgt " \
                "       , opc_node_names    node " \
                "       , (SELECT distinct ng.NODE_ID, realm.MSG_GROUP_NAME from OPC_OP_REALM realm, OPC_NODES_IN_GROUP ng where ng.NODE_GROUP_ID =  realm.NODE_GROUP_ID AND realm.USER_ID IN (select USER_ID from OPC_USER_DATA where NAME Like '%ST_API%' )) resp " \
                "        , (SELECT anno.message_number message_number, atxt.text_part as anno_text " \
                    "           FROM   (SELECT   message_number, MAX(anno_number) as anno_number " \
                    "                   FROM     opc_hist_annotation " \
                    "                   GROUP BY message_number) manno, " \
                    "                   opc_hist_annotation anno, " \
                    "                   opc_hist_anno_text atxt " \
                    "           WHERE  manno.message_number    =    anno.message_number " \
                    "             AND  manno.anno_number       =    anno.anno_number " \
                    "             AND  anno.anno_text_id       =    atxt.anno_text_id " \
                    "             AND  atxt.order_number       =    1) ann " \
                "  WHERE    msg.node_id             =  node.node_id AND      node.node_id            = resp.NODE_ID " \
                "  AND      msg.Message_Group       = resp.MSG_GROUP_NAME  AND    msg.message_number      =  msgt.message_number " \
                "  AND    msg.message_number      =  ann.message_number(+) " \
                "  AND    msgt.order_number       =  1 " \
                "  AND    msg.ackn_user  NOT IN ('OpC')" \
                " AND     msg.local_creation_time >= (sysdate - 7) " \
                " UNION " \
                "      SELECT decode(msg.severity,1,'Unknown',2,'Normal',4,'Warning',8,'Critical',16,'Minor',32,'Major') as Severity " \
                "       , msg.dupl_count    as Dupl_count " \
                "       , TO_CHAR(msg.local_creation_time,'DD-Mon-YYYY HH24:MI:SS') as Creation_Time " \
                "       , TO_CHAR(msg.local_last_time_received,'DD-Mon-YYYY HH24:MI:SS') as Last_Received " \
                "       , node.node_name    as Node_Name " \
                "       , msg.application   as Application " \
                "       , msg.object        as Object " \
                "       , msg.message_group as Message_Group " \
                "       , msgt.text_part    as Message_Text " \
                "       , ann.anno_text     as Last_Annotation " \
                "      FROM  OPC_ACT_MESSAGES msg " \
                "       , OPC_MSG_TEXT msgt " \
                "       , opc_node_names    node " \
                "       , (SELECT distinct ng.NODE_ID, realm.MSG_GROUP_NAME from OPC_OP_REALM realm, OPC_NODES_IN_GROUP ng where ng.NODE_GROUP_ID =  realm.NODE_GROUP_ID AND realm.USER_ID IN (select USER_ID from OPC_USER_DATA where NAME Like '%ST_API%')) resp " \
                "        , (SELECT anno.message_number message_number, atxt.text_part as anno_text " \
                    "           FROM   (SELECT   message_number, MAX(anno_number) as anno_number " \
                    "                   FROM     OPC_ANNOTATION " \
                    "                   GROUP BY message_number) manno, " \
                    "                   OPC_ANNOTATION anno, " \
                    "                   OPC_ANNO_TEXT atxt " \
                    "           WHERE  manno.message_number    =    anno.message_number " \
                                         "             AND  manno.anno_number       =    anno.anno_number " \
                    "             AND  anno.anno_text_id       =    atxt.anno_text_id " \
                    "             AND  atxt.order_number       =    1) ann " \
                "  WHERE    msg.node_id             =  node.node_id " \
                "  AND      node.node_id            = resp.NODE_ID " \
                "  AND      msg.Message_Group       = resp.MSG_GROUP_NAME " \
                "  AND    msg.message_number      =  msgt.message_number " \
                "  AND    msg.message_number      =  ann.message_number(+) " \
                "  AND    msgt.order_number       =  1 " \
                "  AND     msg.local_creation_time >= (sysdate - 7)  " \
                " )  order by Creation_Time "`

when i execute this in script i get error

Quote:
/tmp/tn3[12]: UNION : not found [No such file or directory]
/tmp/tn3[13]: AND msg.local_creation_time >= (sysdate - 7) : not found [No such file or directory]
but when i take echo part and simply execute it in shell it works fine.
dont know what i am doing wrong here
# 2  
Old 07-07-2017
Try without the echo ` `
Code:
QUERY="Select Severity,Dupl_count,Creation_Time,Last_Received,Node_Name,Node_Name,Object,Message_Group,Message_Text,Last_Annotation from " \
...
      " )  order by Creation_Time "

# 3  
Old 07-07-2017
Also, any characters after the \ will cause it to fail, including carriage returns. So if you're saving your scripts from Microsoft Notepad that's a problem.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. UNIX for Dummies Questions & Answers

Shell script not working but command works in command prompt

Hi everyone I have a problem with my script If I try directly this command /usr/bin/nice -n 19 mysqldump -u root --password="******" wiki_schneider -c | nice -n 19 gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz It works But if I simply add this command in a script and... (8 Replies)
Discussion started by: picemma
8 Replies

3. Shell Programming and Scripting

Echo not working with $

$cat FILE.txt $PATH1/file1.txt $PATH2/file2.txt where$PATH 1 = /root/FILE_DR/file1.txt $PATH 2 = /root/FILE_DR/file2.txt for I in `cat FILE.txt` do v=`echo $I` echo $v if then rm $v (5 Replies)
Discussion started by: ekharvi
5 Replies

4. Shell Programming and Scripting

How to echo output of a UNIX command (like ls -l ) using shell script.?

How do i echo the output of a unix command using shell script??? Like: echo /etc/ ls -l (2 Replies)
Discussion started by: sunny2802
2 Replies

5. Shell Programming and Scripting

echo two variables like the paste command is not working

Dear all, I have two files like this file1 A B C D E F file2 1,2 3,4 5,6 I want this output output_expected A B 1,2 C D 3,4 E F 5,6 (3 Replies)
Discussion started by: valente
3 Replies

6. Shell Programming and Scripting

echo is not working as expected

for i in `cat /export/home/afahmed/Arrvial_time.txt` do echo $i echo $i | awk '$3 < $D { print $4 }' >> dynamic_DF.txt; done When i echo, its echo as Nov 15 02:24 /export/home/pp_adm/inbound//wwallet_20111115.txt where i expect it to be Nov 15 02:24... (7 Replies)
Discussion started by: afahmed
7 Replies

7. Shell Programming and Scripting

help with shell script: cp command not working, but mv command works...

Hello. I would like to ask your help regarding the cp command. We are using a cp command to create a back-up copy of our file but to no avail. It's just not working. We already checked the file and directory permissions and all seems correct. We have a script (ftp.script) which calls on... (1 Reply)
Discussion started by: udelalv
1 Replies

8. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

9. Shell Programming and Scripting

why the set rr='echo string|cut not working

I am new to the c shell script, can you let me know why the set rr= is not working. C shell script #! /bin/csh Set tt= 12345_UMR_BH452_3_2.txt set rr='echo $tt | cut –d”_” -f1' syntax error (4 Replies)
Discussion started by: jdsignature88
4 Replies

10. Shell Programming and Scripting

Echo working funny

Hello, this is my first post and question. I have search before for this problem but didn't find anything similar. My case: I have a string inside the variable string1 like this: string1="lala lele lili lolo lulu" When I do echo of it, it appears like this: echo $string1 lala lele lili... (8 Replies)
Discussion started by: hemtar
8 Replies
Login or Register to Ask a Question