0

I have the following bash script which is supposed to call sqlplus with the current date.

#!/bin/bash

DATE='date +%F'

sqlplus -s << EOF1
DB_username/DB_password
set heading off
exec PLSQL_PROCEDURE('$DATE', '-30','someString','/home/outputFolder');
exit
EOF1

exit

I get the following error however- it's definitely not evaluating the date command:

BEGIN PLSQL_PROCEDURE('date +%F', '-30', 'someString', '/home/outputFolder'); END;

*
ERROR at line 1:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0
ORA-06512: at "DataBaseName.PLSQL_PROCEDURE", line 19
ORA-06512: at line 1

How can I fix it so that it passes the current date in, like this?

PLSQL_PROCEDURE('2013-03-14', '-30', 'someString', '/home/outputFolder');

1 Answer 1

1

Try this instead :

#!/bin/sh

DATE=$(date +%F) # note the $( ) form

sqlplus -s  << EOF1
DB_username/DB_password
set heading off
exec PLSQL_PROCEDURE('$DATE', '-30','someString','/home/outputFolder');
exit
EOF1

You should learn about Command Substitution: The $(foo bar) causes the command 'foo' to be executed with the argument 'bar' and $(..) will be replaced by the output. See http://mywiki.wooledge.org/BashFAQ/002

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.