![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to include RETURN KEY with Background process "&" in Shell Script | racbern | Shell Programming and Scripting | 1 | 03-11-2008 03:30 AM |
| passing a list of dynamic names to a "PS" command in shell script? | sachin.tendulka | Shell Programming and Scripting | 3 | 11-21-2007 12:18 AM |
| Q: Recording shell script screen output using "script" command ? | lalfonso.gomez | Shell Programming and Scripting | 4 | 01-18-2007 05:31 PM |
| Shell Script fails with "can't connect to client" | sseenu79 | HP-UX | 2 | 12-20-2006 06:47 AM |
| No utpmx entry: you must exec "login" from lowest level "shell" | peterpan | UNIX for Dummies Questions & Answers | 0 | 01-18-2006 12:15 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
| Forum Sponsor | ||
|
|
|
|||
|
Nice job especially since it works so well for you.
One question. Why are you exporting every one of your variables? By the way, you can give yourself a bit of a short cut and avoid the unnecessary second sqlplus session by using a little different technique. This one uses an array. Code:
set -A DATE_ARRAY $(
sqlplus -s /nolog <<EOF
connect user/password
set pages 0 feedback off verify off echo off head off
select to_char(sysdate, 'MMDDYYYY') || '235959'
,to_char(sysdate-1, 'MMDDYYYY') || '000000'
from dual;
EOF
)
sqlplus /nolog <<EOF > /dev/null
connect user/password@yourotherdatabase
set ... your output parameters
spool ...
SELECT ...
FROM yourtable
WHERE date_column between to_date('${DATE_ARRAY[2]}', 'MMDDYYHH24MISS')
and to_date('${DATE_ARRAY[1]}', 'MMDDYYHH24MISS');
spool off
EOF
Code:
sqlplus /nolog <<EOF > /dev/null
connect user/password@yourotherdatabase
set ... your output parameters
REM This will create variables that can be used in the second SQL
COLUMN BDATE NEW_VALUE BDATE
COLUMN EDATE NEW_VALUE EDATE
SELECT to_char(sysdate, 'MMDDYYYY') || '235959' EDATE
,to_char(sysdate-1, 'MMDDYYYY') || '000000' BDATE
FROM DUAL;
spool yourfilename&&BDATE...
SELECT ...
FROM yourtable
WHERE date_column between to_date('&&BDATE', 'MMDDYYHH24MISS')
and to_date('&&EDATE', 'MMDDYYHH24MISS');
spool off
EOF
Last edited by tmarikle; 10-05-2005 at 08:19 AM. Reason: Left out the real point of example 2 where the variable is used for the filename. |
|
||||
|
[Oracle] "Dynamic" sql / Shell script
Quote:
1) Configuration management 1.A) I first code/test my work using the env variables of my dev/qa server/environment such Oracle DB user name/password, Oracle TNS name, directory name(s) etc. 1.B) One my qa is completed, I push my shell script to my prod server. The variables still have identical names as in `dev`; however, I can/do change the values of each variable to match my `prod` environment e.g. Oracle DB user name/password, Oracle TNS name, directory name(s) etc. 2) Security 2.A) The shell scripts have a chmod value which allows anybody that's not me (ie. my Unix id) to read the code. However, the chmod value of my ETL.LIB file make it so that it can only view/modified by me and the root user. Stuff like passwords, file/directory names etc is hidden from most people. 3) Simplicity 3.A) I have 214 shell scripts like the one I posted. Some are wrappers to SQL*Loader jobs, others to SQL*scripts...It is a lot easier for me to manage changes by editing one single file (ETL.LIB...as opposed to each one of them) whenever our DBA feels like changing passwords, TNS names or when our sysadmin decides to mount a new file system etc... That's about it. PS: Thanks for the kind comments. |
|
||||
|
Quote:
I like this. it is really clever example since you're able to accompliish the same thing as me in one single shot. Thanks for your input!! Alan |
||||
| Google The UNIX and Linux Forums |