1834424 Members
1860 Online
110067 Solutions
New Discussion

Re: Shell script problem

 
SOLVED
Go to solution

Shell script problem

I wrote the following script:
#!/bin/ksh
. /u01/app/oracle/.profile
TODAY=`date +'D%y%m%d.T%H%M%S'`
ORACLE_HOME=/u01/app/oracle/product/9.2.0
PATH=$ORACLE_HOME/bin
ORACLE_SID=TTWB
/bin/mkdir /u29/backup/ARC"$TODAY"
/bin/chmod 755 /u29/backup/ARC$TODAY
ARC_FILE=/tmp/archive.$TODAY.lst
/usr/bin/compress /u25/arch/*
$PATH/sqlplus /nolog <connect sys/ttwbsys as sysdba
archive log stop;
!/bin/cp -R `/bin/cat $ARC_FILE` /u29/backup/ARC$TODAY

It gave the following error:
SQL*Plus: Release 9.2.0.1.0 - Production on Thu Aug 28 16:33:43 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

SQL> Connected.
SQL> ORA-00250: archiver not started
SQL> then: then/endif not found.
Usage: cp [-f|-i] [-p] [-S] [-e warn|force|ignore] source_file target_file
cp [-f|-i] [-p] [-S] [-e warn|force|ignore] source_file ... target_directory
cp [-f|-i] [-p] [-S] -R|-r [-e warn|force|ignore] source_directory ... target_directory

SQL> Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.1.0 - Production

If I rewrite the script as follow:

#!/bin/ksh
. /u01/app/oracle/.profile
TODAY=`date +'D%y%m%d.T%H%M%S'`
ORACLE_HOME=/u01/app/oracle/product/9.2.0
PATH=$ORACLE_HOME/bin
ORACLE_SID=TTWB
/bin/mkdir /u29/backup/ARC"$TODAY"
/bin/chmod 755 /u29/backup/ARC$TODAY
ARC_FILE=/tmp/archive.$TODAY.lst
/usr/bin/compress /u25/arch/*
$PATH/sqlplus /nolog <connect sys/ttwbsys as sysdba
archive log stop;
exit
/bin/cp -R `/bin/cat $ARC_FILE` /u29/backup/ARC$TODAY

It does not do the last line at all. Help please.
4 REPLIES 4
John Dvorchak
Honored Contributor

Re: Shell script problem

It doesn't do the last line because you have and "exit" as the next to the last line. When the script hits that exit command, it exits without further processing.
If it has wheels or a skirt, you can't afford it.
Steven E. Protter
Exalted Contributor

Re: Shell script problem

The last line in the second script does not execute because of the exit right above it.

Replace the exit with this

EOF

Then it will work.
#!/bin/ksh
. /u01/app/oracle/.profile
TODAY=`date +'D%y%m%d.T%H%M%S'`
ORACLE_HOME=/u01/app/oracle/product/9.2.0
PATH=$ORACLE_HOME/bin
ORACLE_SID=TTWB
/bin/mkdir /u29/backup/ARC"$TODAY"
/bin/chmod 755 /u29/backup/ARC$TODAY
ARC_FILE=/tmp/archive.$TODAY.lst
/usr/bin/compress /u25/arch/*
$PATH/sqlplus /nolog <connect sys/ttwbsys as sysdba
archive log stop;
EOF
/bin/cp -R `/bin/cat $ARC_FILE` /u29/backup/ARC$TODAY


SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven E. Protter
Exalted Contributor
Solution

Re: Shell script problem

Don't point my previous post. Here is acorrected version. Leave the exit alone.

The last line in the second script does not execute because of the exit right above it.




Then it will work.
#!/bin/ksh
. /u01/app/oracle/.profile
TODAY=`date +'D%y%m%d.T%H%M%S'`
ORACLE_HOME=/u01/app/oracle/product/9.2.0
PATH=$ORACLE_HOME/bin
ORACLE_SID=TTWB
/bin/mkdir /u29/backup/ARC"$TODAY"
/bin/chmod 755 /u29/backup/ARC$TODAY
ARC_FILE=/tmp/archive.$TODAY.lst
/usr/bin/compress /u25/arch/*
$PATH/sqlplus /nolog <connect sys/ttwbsys as sysdba
archive log stop;
exit;
EOF
/bin/cp -R `/bin/cat $ARC_FILE` /u29/backup/ARC$TODAY


SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com

Re: Shell script problem

Thanks SEP. exit and EOF worked perfectly. I ahve been struggling with this for a while. Hats off.