and pass the file name to the data base query get the diretory for that file and move the file to that directory.
This will give diretory information
dir_paths=`sqlplus -s $DB_CONNECTION/$PASS_WORD << EOF
set termout off;
set verify off;
set feedback off;
set heading off;
set newpage 0;
set pagesize 0;
set linesize 200;
SELECT SUBSTR(trunk_path,3,INSTR(trunk_path,'sql')) FROM directory_map
WHERE object_name=SUBSTR(UPPER('$1'),1,INSTR(UPPER('$1'),'.')-1);
exit success;
EOF`
Thanks for your reponse.
I am able to build the script for my requirement.
I am executing the follwig script in cygwin bash.
But I am facing some issue it's weird for me. Not able to resolve it.
dir_paths=`sqlplus -s $DB_CONNECTION/$PASS_WORD << EOF
set termout off;
set verify off;
set feedback off;
set heading off;
set newpage 0;
set pagesize 0;
set linesize 200;
SELECT SUBSTR(trunk_path,3,INSTR(trunk_path,'sql')) FROM directory_map
WHERE object_name=SUBSTR(UPPER('$1'),1,INSTR(UPPER('$1'),'.')-1);
exit success;
EOF`
echo $dir_paths
sfsmde/sql
That \r (= ^M, 0x0D, <CR>) char is part of the DOS/windows line terminator <CR><NL> . As *nix uses <NL> only, it considers \r as part of the file name. To get rid of it, use e.g. dos2unix . What surprises me is that cygwin seems not to know how to handle it.
Thanks a lot.
The issue has been resolved.
How to get another column values of SQL query to another variable.
I have added column new_file_name in my query.
While moving te file I have to move with new file name.
dir_paths=`sqlplus -s $DB_CONNECTION/$PASS_WORD << EOF
set termout off;
set verify off;
set feedback off;
set heading off;
set newpage 0;
set pagesize 0;
set linesize 200;
SELECT SUBSTR(trunk_path,3,INSTR(trunk_path,'sql')),new_file_name FROM directory_map
WHERE object_name=SUBSTR(UPPER('$1'),1,INSTR(UPPER('$1'),'.')-1);
exit success;
EOF`
mv file_name $dir_paths/$new_file_name
Please help me.
Thanks in advance.
---------- Post updated at 05:12 PM ---------- Previous update was at 04:08 PM ----------
I'm afraid I can't as I absolutely don't understand your request (see post#2). Any comment up to now was just shooting in the dark - and neither has (yet) been approved nor disapproved.
sqlplus -s $DB_CONNECTION/$PASS_WORD << EOF
set termout off;
set verify off;
set feedback off;
set heading off;
set newpage 0;
set pagesize 0;
set linesize 200;
SELECT SUBSTR(trunk_path,3,INSTR(trunk_path,'sql')),new_file_name FROM directory_map
WHERE object_name=SUBSTR(UPPER('$1'),1,INSTR(UPPER('$1'),'.')-1);
exit success;
EOF
produce? Is it one line with a space or tab between the selected part of the trunk_path and the new_file_name ; or do those values appear on separate lines?
Does the output contain any quoting characters around the strings produced?
What operating system and shell are you using? On many shells, the script you showed us would generate a syntax error for an unterminated here-document.
Did you get any diagnostic messages when you ran the script you showed us in post #5?
What command line did you use to invoke your script?