Re: [Nolug] bash problem

From: Jess Planck <jesse.planck_at_gmail.com>
Date: Fri, 26 Jul 2013 13:32:39 -0500
Message-Id: <1C305DE6-B1A8-4029-9FE2-99EF04EA69A7@gmail.com>

Don't get to play with oracle too much, so I don't know the required formatting for your sqlplus command. I do know the trickiness of bash and string variable expansion though since I do some quick ugly work with MySQL other cryptic utilities on the command line like good ole rsync. I stripped your script down to the basics for this issue and used "echo" to replace your "sqlplus" command.

#!/bin/bash
TARGET_ACCOUNT=TORY4
echo / ' as sysdba' "SELECT username, expiry_date from dba_users where username = ${TARGET_ACCOUNT} and round (expiry_date - sysdate < 11);"

If you can switch from your multiline variable for SQL input to a single "quoted" line, you can use variable expansion above. Never played with HEREDOC multiline variables in bash before but know the headache in php, so this is an interesting exploration. Apparently you can run a variable through cat and return an expanded variable if you must live by HEREDOC.

#!/bin/bash
TARGET_ACCOUNT=TORY4

VAR=$(cat <<END_HEREDOC
try the ${TARGET_ACCOUNT}
END_HEREDOC
)

echo "$VAR"

Have fun!
Jess

On Jul 26, 2013, at 12:46 PM, Diann Smith <diann170@gmail.com> wrote:

> thanks for the info. but I did try , still no luck.
>
> SELECT username, expiry_date
> from dba_users
> where username = ${TARGET_ACCOUNT}
> #and round (expiry_date - sysdate < 11);
> SQL> SP2-0734: unknown command beginning "#select us..." - rest of line ignored.
> SQL> SP2-0042: unknown command "#exit" - rest of line ignored.
> SQL> SP2-0042: unknown command "#EOF" - rest of line ignored.
> SQL> SQL> SQL> SQL> 2 3 4 SP2-0734: unknown command beginning "and round ..." - rest of line ignored.
> by the way, it works up to the from dba_users., but when I add the where username......
> I get those errors.
>
> Thanks for checking
>
> Barbara
> On Fri, Jul 26, 2013 at 11:37 AM, Jess Planck <jesse.planck@gmail.com> wrote:
>
> How bout variable expansion with curly brackets? Like ${MY_VAR}
>
> http://stackoverflow.com/questions/8748831/bash-why-do-we-need-curly-braces-in-variables
>
> Jess
>
>
> On Jul 26, 2013, at 11:26 AM, Diann Smith <diann170@gmail.com> wrote:
>
>> sorry I typed that in wrong. I checked and it is corrcet. but it still won't run???
>> errors
>>
>> SELECT username, expiry_date
>> from dba_users
>> where username = $TARGET_ACCOUNT
>> #and round (expiry_date - sysdate < 11);
>>
>> Connected to:
>> Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
>> With the Partitioning, OLAP, Data Mining and Real Application Testing options
>> SQL> SP2-0734: unknown command beginning "#select us..." - rest of line ignored.
>> SQL> SP2-0042: unknown command "#exit" - rest of line ignored.
>> SQL> SP2-0042: unknown command "#EOF" - rest of line ignored.
>> SQL> SQL> SQL> SQL> 2 3 4 SP2-0734: unknown command beginning "and round ..." - rest of line ignored.
>>
>>
>>
>> On Fri, Jul 26, 2013 at 11:00 AM, Brad Bendily <bendily@gmail.com> wrote:
>> From your code, you left out an C in account.
>> "where username = $TARGET_ACOUNT"
>>
>>
>>
>>
>> On Fri, Jul 26, 2013 at 10:51 AM, Diann Smith <diann170@gmail.com> wrote:
>> I am a newbi and I have a problem trying to run this code. I am trying to put a unix variable - (Target_account)
>> into a bash/unix scritpt. If anyone could help I would appreciate it.
>>
>> Thanks
>> diann
>> #!/bin/bash
>>
>> TARGET_ACCOUNT=TORY4
>> TARGET_DATABASE=testbat
>> RS=samp.lst
>> . ${MMS_LOCAL}/etc/env_testbat.sh
>> echo SID=$ORACLE_SID
>> sqlplus / ' as sysdba' <<EOF
>>
>> SELECT username, expiry_date
>> from dba_users
>> where username = $TARGET_ACOUNT
>> and round (expiry_date - sysdate < 11);
>> EOF
>>
>>
>>
>> --
>> Have Mercy & Say Yeah
>>
>
>

___________________
Nolug mailing list
nolug@nolug.org
Received on 07/26/13

This archive was generated by hypermail 2.2.0 : 07/27/13 EDT