Oracle expdp CentOS 6.2 Shell script unusual behavior - New line gives command not found
-
20-06-2021 - |
Question
My first post be gentle.
I have the script below which was taken out of a RedHat 5.3 box to backup an Oracle database. The script was working fine on the Redhat 5.3 box. I then used it as a reference to backup an oracle db on a centos 6.2 box and modified it as required.
#!/bin/bash
ORACLE_HOME="/u01/app/oracle/product/11.2.0/db_1"
NLS_LANG=AMERICAN_AMERICA.AR8ISO8859P6
BKDATE=`date "+%Y-%m-%d_%H-%M-%S"`
C1="system/password@dbname DIRECTORY=RMBACKUP SCHEMAS=USER1,USER2,USER3 DUMPFILE=dbname_"
C2="_full_pump.dmp LOGFILE=dbname_"
C3="_full_pump.log"
BKCMD=$C1$BKDATE$C2$BKDATE$C3
echo $C1
echo $C2
echo $C3
echo $BKDATE
echo $BKCMD
#run the exp backup
$ORACLE_HOME/bin/expdp $BKCMD
The weird bahavior is that when I execute the script the new line causes a command not found error and the concatenation gets merged as seen below.
system/password@dbname DIRECTORY=RMBACKUP SCHEMAS=USER1,USER2,USER3 DUMPFILE=dbname_
_full_pump.dmp LOGFILE=dbname_
_full_pump.log
2012-07-10_09-39-06
system/password@dbname DIRECTORY=RMBACKUP SCHEMAS=USER1,USER2,USER3 DUMPFI_full_pump.log39-06ILE=dbname_
/bin/expdp: No such file or directoryacle/product/11.2.0/db_1
The date merging with the other text is not a typo, that is the echo output.
I added set -x at the beginning and here is the output
+ ORACLE_HOME=$'/u01/app/oracle/product/11.2.0/db_1\r'
+ NLS_LANG=$'AMERICAN_AMERICA.AR8ISO8859P6\r'
++ date +%Y-%m-%d_%H-%M-%S
+ BKDATE=$'2012-07-10_10-27-45\r'
+ C1='system/password@dbname DIRECTORY=RMBACKUP SCHEMAS=USER1,USER2,USER3 DUMPFI'E=dbname_
' C2='_full_pump.dmp LOGFILE=dbname_
+ C3=_full_pump.log
+ BKCMD='system/password@dbname DIRECTORY=RMBACKUP SCHEMAS=USER1,USER2,USER3 DUM_full_pump.log'7-45ILE=dbname_
+ echo system/password@dbname DIRECTORY=RMBACKUP SCHEMAS=USER1,USER2,USER3 $'DUMPFILE=dbname_\r'
system/password@dbname DIRECTORY=RMBACKUP SCHEMAS=USER1,USER2,USER3 DUMPFILE=dbname_
+ echo _full_pump.dmp $'LOGFILE=dbname_\r'
_full_pump.dmp LOGFILE=dbname_
+ echo $'_full_pump.log\r'
_full_pump.log
+ echo $'2012-07-10_10-27-45\r\r'
2012-07-10_10-27-45
+ echo system/password@dbname DIRECTORY=RMBACKUP SCHEMAS=USER1,USER2,USER3 $'DUMPFILE=dbname_\r2012-07-10_10-27-45\r_full_pump.dmp' $'LOGFILE=dbname_\r2012-07-10_10-27-45\r_full_pump.log\r'
system/password@dbname DIRECTORY=RMBACKUP SCHEMAS=USER1,USER2,USER3 DUMPFILE=dbn_full_pump.log27-45ILE=dbname_
+ $'/u01/app/oracle/product/11.2.0/db_1\r/bin/expdp' system/password@dbname DIRECTORY=RMBACKUP SCHEMAS=USER1,USER2,USER3 $'DUMPFILE=dbname_\r2012-07-10_10-27-45\r_full_pump.dmp' $'LOGFILE=dbname_\r2012-07-10_10-27-45\r_full_pump.log\r'
/bin/expdp: No such file or directoryacle/product/11.2.0/db_1
Waiting for responses...
Solution
As you can see, there are '\r'
characters in the texts. Probably you edited the file with an editor that adds \r
at the end of lines automatically. You must edit the file once again and remove these characters.