Help for resolving Unexpected EOF while assigning value to variable


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Help for resolving Unexpected EOF while assigning value to variable
# 1  
Old 11-15-2017
Help for resolving Unexpected EOF while assigning value to variable

Code:
#!/bin/sh
. /opt/ora/oracle/db/tech_st/11.2.3/PROD_proddb.env
sqlplus -s "username/password" << EOF
no='sqlplus -s username/password<<EOF
set heading off
set feedback off
Select 
pt.user_concurrent_program_name report_name , OUTFILE_NAME report_path 
FROm 
apps.fnd_concurrent_programs_tl pt, 
apps.fnd_concurrent_requests f 
where 
pt.concurrent_program_id = f.concurrent_program_id 
and pt.application_id = f.program_application_id 
and f.RESPONSIBILITY_ID = 52431 
and trunc(f.request_date) = trunc(sysdate);
exit
EOF
`
report_name=`echo $no | awk `{print $report_name}``
report_path=`echo $no | awk `{print $report_path}``
$ echo report_name
$ echo report_pathwhile running above script, shows below errors
-bash: /home/oracle/scripts/test2.sh: line 21: unexpected EOF while looking for matching ``'
-bash: /home/oracle/scripts/test2.sh: line 25: syntax error: unexpected end of file


Last edited by Scott; 11-15-2017 at 09:45 AM.. Reason: Code tags
# 2  
Old 11-15-2017
Well, the first thing that jumps out is that you're using backticks (`) instead of single quotes (') around your awk commands, and an erroneous backtick after the closing EOF for your SQLPlus call.

Generally speaking, it's better to use $(...) for command substitution than backticks.. it's also easier to read!

Using $report_name and $report_path inside your awk won't work, as they're shell variables, and not awk variables (and in awk, using $ before them would make them equate to the position of a variable, not the variable itself). You might find what you're looking for in positional variables ($1, $2, etc.) inside the awk, or you might not need awk at all, depending on, actually, what output you are looking for.

It's bad practice to put a username / password on the command's line like this - it will show up in processes (e.g. when using ps).
This User Gave Thanks to Scott For This Post:
# 3  
Old 11-15-2017
Code:
#!/bin/sh
. /opt/ora/oracle/db/tech_st/11.2.3/PROD_proddb.env
sqlplus -s "apps/apps" << EOF
no='sqlplus -s apps/apps<<EOF
set heading off
set feedback off
Select 
pt.user_concurrent_program_name report_name , OUTFILE_NAME report_path 
FROm 
apps.fnd_concurrent_programs_tl pt, 
apps.fnd_concurrent_requests f 
where 
pt.concurrent_program_id = f.concurrent_program_id 
and pt.application_id = f.program_application_id 
and f.RESPONSIBILITY_ID = 52431 
and trunc(f.request_date) = trunc(sysdate);
exit
EOF
report_name=`echo $no | awk '{print $report_name}'`
report_path=`echo $no | awk '{print $report_path}'`
$ echo report_name
$ echo report_path

after corrections, shell shows query output. but not store and display query results in variables and show below error
Code:
-bash: $: command not found
-bash: $: command not found


Last edited by RudiC; 11-15-2017 at 10:07 AM.. Reason: Code tags
# 4  
Old 11-15-2017
Two have two << EOFs. The first SQLPlus command looks to be erroneous, and the opening of the command substitution around the other one is a single quote (') not a backtick (`).

More readable would be:
Code:
no=$(sqlplus -s << EOF
conn user/pass
...
EOF
)

Instead of the two awk commands, if you're sure that $no contains exactly only those two words, you need, there are other, simpler ways to get that.

For example
Code:
set - $no
report_name=$1
report_path=$2

Please don't just put [CODE][/CODE] at the top of your post and assume that's "using code tags". They're supposed to go [CODE]around the code[/CODE]!
This User Gave Thanks to Scott For This Post:
# 5  
Old 11-15-2017
Code:
#!/bin/sh
. /opt/ora/oracle/db/tech_st/11.2.3/PROD_darwin.env
#sqlplus -s "apps/apps" << EOF
no=$(sqlplus -s apps/apps<<EOF
set heading off
set feedback off
Select 
pt.user_concurrent_program_name report_name , OUTFILE_NAME report_path 
FROm 
apps.fnd_concurrent_programs_tl pt, 
apps.fnd_concurrent_requests f 
where 
pt.concurrent_program_id = f.concurrent_program_id 
and pt.application_id = f.program_application_id 
and f.RESPONSIBILITY_ID = 52431 
and trunc(f.request_date) = trunc(sysdate);
exit
EOF
)
report_name=`echo $no | awk '{print $report_name}'`
report_path=`echo $no | awk '{print $report_path}'`
$ echo report_name
$ echo report_path

make changes in the script and after running below error occours
Code:
[oracle@darwin ~]$ . /home/oracle/scripts/test2.sh
-bash: $: command not found
-bash: $: command not found


Last edited by Scott; 11-15-2017 at 10:29 AM.. Reason: Code tags again..
# 6  
Old 11-15-2017
Remove the $ before the echo commands at the end of the script.
This User Gave Thanks to Scott For This Post:
# 7  
Old 11-15-2017
now after removing $ script output shows Query results. but variable report_name and report_path shows blank. below is the output.
Code:
[oracle@darwin ~]$ . /home/oracle/scripts/test2.sh
SP2-0734: unknown command beginning "no='sqlplu..." - rest of line ignored.

Cotton Stock Report (Net Weight)- Customized
/opt/ora/oracle/inst/apps/PROD_darwin/logs/appl/conc/out/o16735454.out

Daily Yarn Clearance Summary Report (NCML / ESML) -Customized
/opt/ora/oracle/inst/apps/PROD_darwin/logs/appl/conc/out/o16735457.out

Lab Test - Customized
/opt/ora/oracle/inst/apps/PROD_darwin/logs/appl/conc/out/o16735462.out

report_name
report_path
[oracle@darwin ~]$


Last edited by Scott; 11-15-2017 at 10:56 AM.. Reason: Use code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unexpected EOF while loooking for matching '"

Hi everyone, I'm really new in shell scripting and having trouble resolving this error. Can someone please tell me why I'm getting these errors? Error Message: ./test.sh: line 50: unexpected EOF while looking for matching `'' ./test.sh: line 53: syntax error: unexpected end of file ... (4 Replies)
Discussion started by: simonirang
4 Replies

2. Shell Programming and Scripting

Unexpected EOF while looking for matching `"'

I have a piece of Linux script. It tells me some syntax error. I couldn't find it. Please help me to identify them. Thanks. The code looks like this: export ORACLE_SID=MYDB export SPW=`cat /opt/oracle/scripts/.sys_pw_$ORACLE_SID` export check_arch=`sqlplus -s << EOF / as sysdba... (7 Replies)
Discussion started by: duke0001
7 Replies

3. Shell Programming and Scripting

eof unexpected while looking[...]

Hello I use opensuse build service to build packages (oh surprise !) I have integrate a command in a spec whose worked and now this exit with: unexpected EOF while looking for matching `"' Command: if \.").mk ]; then ln -s $(pwd)/mozilla/security/coreconf/Linux2.6.mk \ ... (5 Replies)
Discussion started by: posophe
5 Replies

4. UNIX for Dummies Questions & Answers

Unexpected EOF in .profile

When opening a new window under Terminal, got that message: Last login: Sun Oct 30 10:35:12 on ttys000 -bash: /Users/MyName/.profile: line 47: syntax error: unexpected end of file I tried several clues like using BBedit or emacs to get rid of it, nothing does. Maybe shell commands cut or... (1 Reply)
Discussion started by: shub22
1 Replies

5. Shell Programming and Scripting

unexpected EOF : BASH

i'm writing a bash script that uploads a file to my server but it keeps saying unexpected EOF... i cannot see the problem with it, and it worked before i edited the script to work on my ipod touch as well. Here is the troublsome code... if ; then tar -czf "file(Mac).tar.gz" "/folder" >... (11 Replies)
Discussion started by: DuskFall
11 Replies

6. Shell Programming and Scripting

Stuck with Unexpected EOF

Hi, i have a script as below. i'm using sun solaris 10. Script : #! /bin/sh load() { find /stage_area/loadfiles/telsims/test/ -type f -name "*$1" -print > /tmp/testfile.txt fc=`cat /tmp/testfile.txt | wc -l | sed 's/ //g'` if ; then echo " Files Not Avaliable" exit else... (12 Replies)
Discussion started by: apple2685
12 Replies

7. UNIX for Dummies Questions & Answers

unexpected EOF

hello everyone...im having this problem with unexpected EOF with line 85 which is..i cant see whats wrong with it..can any1 plz help me out. read -p "$p1 please enter the number of tries you wish to have:" lifeline function main() { guessnum=0 read -p "Please enter if its sinle player game... (1 Reply)
Discussion started by: Freakhan
1 Replies

8. Shell Programming and Scripting

Unexpected EOF while looking for matching `"'

Hi everyone, I am trying to search for a string in a file that is partly made up of a variable. Here's the code: echo "parentCategory = $parentCategory" echo "parentCategoryFormatted = $parentCategoryFormatted" numUrlsFoundInParentCategory=`grep -c "<Topic r:id=\"Top\/World\/Français\/"... (2 Replies)
Discussion started by: BlueberryPickle
2 Replies

9. UNIX for Advanced & Expert Users

unexpected EOF

I ran the following scripts and everytime i get the errot as follows Line 54: unexpected EOF while looking for matching ',' line 57 syntex error unexpected end of file#!/bin/ksh set -x BKUP_DIR=/u03/backups/abu/nightly_backup LOG_FILE=/u03/backups/abu/backup.log ORACLE_HOME=... (9 Replies)
Discussion started by: manna
9 Replies

10. Shell Programming and Scripting

Unexpected eof error

Hi, I am newbie and am just trying to connect to oracle from shell script ,,,but I am getting the following error ./prog.sh: line 20: syntax error: unexpected end of file The scripts is : #!/bin/bash O=$IFS; IFS=","; while read a b c d do echo $c ... (6 Replies)
Discussion started by: thana
6 Replies
Login or Register to Ask a Question