Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

su within same script 1

Status
Not open for further replies.
Nov 12, 2004
44
US
Oracle rman backup with Netbackup.

The problem is that unlike TSM you cannot put the 'su - oracle -c scriptname' inside the scheduler and have it run. The only way I have found so far is to write a script that does an 'su - oracle -c "scriptname"' to have scriptname run. Can anyone think of a way to su to oracle and have the script run within the same script?

I don't want to create multiple su scripts to do this.

The rman script
Code:
#!/bin/ksh

export scripts=/`uname -n`/oracle/scripts
. $scripts/set_localqnoldv01.sh
###############################################################
cd $scripts
export RMAN_LOG=$scripts/logs/Rarch_${ORACLE_SID}_$(date +%m%d%y_%T).log
export JOB_TYPE=" Arch only "
find $scripts/scripts -name ${ORACLE_SID}_del_arch_back.scr -exec rm {} \; >/dev/null
cat <<EOF > $scripts/scripts/${ORACLE_SID}_del_arch_back.scr
run {
sql 'alter system checkpoint' ;
allocate channel dev1 type 'SBT_TAPE' 
send 'NB_ORA_POLICY=oracle_`hostname` , NB_ORA_SERV=nbuhost' ;
allocate channel dev2 type 'SBT_TAPE' 
send 'NB_ORA_POLICY=oracle_`hostname` , NB_ORA_SERV=nbuhost' ;
sql 'alter system checkpoint' ;
sql 'alter system archive log current';
backup
    filesperset 40
    format 'al_%d_$(date +%H%M_%d%m%y)_%s_%p'
    (archivelog from time '08 OCT 2004 11:25:00' until time 'SYSDATE' delete input) ;
release channel dev1 ;
release channel dev2 ;
    }
###############################################################
EOF
echo "Job Started at:" `date +(%b %d %T) |cut -c2-16` > $RMAN_LOG
$CATALOG cmdfile=$scripts/${ORACLE_SID}_del_arch_back.scr msglog=$RMAN_LOG append
echo " Completed at:" `date +(%b %d %T) |cut -c2-16` >> $RMAN_LOG
find $scripts/ -name ${ORACLE_SID}_del_arch_back.scr -exec rm {} \; >/dev/null
 
a way to su to oracle and have the script run within the same script
case $(id | awk 'BEGIN{FS="[()]"}{print $2}') in
oracle) : OK;;
*) for arg; do args=$args" '$arg'"; done
exec su - oracle -c "export PATH=$PATH;exec $0 $args";;
esac

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for that, however, it still will not exec the su to oracle. This is solaris 9. Thanks.
 
Have you tried set -x before the case line to see in stderr the trace of what is executed ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I tried that and will execute the 'cd $scripts' but nothing after that. But, I don't think it is running that as Oracle.

When I tried this it won't print the SID.
Code:
#!/bin/ksh
su - oracle -c "
        print ${ORACLE_SID}
        "

But this will print hello. But again, I don't think it is as oracle.
Code:
#!/bin/ksh
su - oracle -c "
        print hello
        "
 
Replace this:
su - oracle -c "
print ${ORACLE_SID}
"
By this:
su - oracle -c '
print ${ORACLE_SID}
'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks. That allows the su to oracle, now it is failing when trying to run cat <<EOF. I put a print after the end EOF but it doesn't get there. Thanks for your help.
 
Seems you have not tried the method I suggested in my first post.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Forgive my ignorance for this question. Using your original suggestion, how would that be used with my rman.rcv script that I posted?

Thanks.
 
#!/bin/ksh
case $(id | awk 'BEGIN{FS="[()]"}{print $2}') in
oracle) : OK;;
*) for arg; do args=$args" '$arg'"; done
exec su - oracle -c "export PATH=$PATH;exec $0 $args";;
esac
export scripts=/`uname -n`/oracle/scripts
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top