Home » Infrastructure » Linux » scripts behave differently
scripts behave differently [message #152933] Wed, 28 December 2005 00:22 Go to next message
tarundua
Messages: 1080
Registered: June 2005
Location: India
Senior Member

I wrote a shell script to spool out the filenames associated with the specified tablespace.

SCRIPT1
## scrpt1.sh
if [ $# -ne 2 ]
 then
     echo invalid arguments
     exit
else
   tblsp_name="$1"
   log_str="sys/$2 as sysdba"
   val=`sqlplus -S "$log_str" <<!
        set heading off
        set feedback off
        spool tmp_fl.out
        select file_name from dba_data_files
        where tablespace_name=upper('$tblsp_name');
        spool off
        !`
fi


the above works perfectly.

but SCRIPT2
## scrpt2.sh
if [ $# -ne 2 ]
 then
     echo invalid arguments
     exit
else
   tblsp_name="$1"
   log_str="sys/$2 as sysdba"
   sqlplus -S "$log_str" <<!
        set heading off
        set feedback off
        spool tmp_fl.out
        select file_name from dba_data_files
        where tablespace_name=upper('$tblsp_name');
        spool off
        !
fi


this generates an error
[oracle@localhost ~]$ ./scrpt2.sh users passwd
./scrpt2.sh: line 18: syntax error: unexpected end of file


the only difference is , assigning the output of sqlplus session to a variable i.e. val (first script).

I want to know why the second script is not working or what i am doing wrong in the second script.

thanks & regards,
tarun
Re: scripts behave differently [message #152965 is a reply to message #152933] Wed, 28 December 2005 02:50 Go to previous messageGo to next message
Frank Naude
Messages: 4579
Registered: April 1998
Senior Member
Hi Tarun,

Try to put the terminating ! in column 1.

Best regards.

Frank
Re: scripts behave differently [message #152966 is a reply to message #152965] Wed, 28 December 2005 02:54 Go to previous messageGo to next message
tarundua
Messages: 1080
Registered: June 2005
Location: India
Senior Member

Hi Frank,

Bingo.. You hit the right spot. I changed the position of ! and look it works perfectly fine.

[oracle@localhost ~]$ ./scrpt2.sh users passwd
/data/dev_database/datafile/users01.dbf 


Any specific reason for this behaviour.

Regards,
tarun
Re: scripts behave differently [message #152969 is a reply to message #152966] Wed, 28 December 2005 02:57 Go to previous messageGo to next message
Frank Naude
Messages: 4579
Registered: April 1998
Senior Member
It's one of those silly rules of shell scripting.

You can tab indent the terminator like this:

sqlplus -S "$log_str" <<-!
        -- Your script
        !


Best regards.

Frank
Re: scripts behave differently [message #152971 is a reply to message #152969] Wed, 28 December 2005 03:04 Go to previous message
tarundua
Messages: 1080
Registered: June 2005
Location: India
Senior Member

Thanks a lot, I will keep it in mind while writing shell scripts.

Regards,
Tarun
Previous Topic: Is Oracle Database Free for Linux?
Next Topic: GPROF tool information
Goto Forum:
  


Current Time: Tue Apr 16 03:12:02 CDT 2024