I have a few linux machines and each of them have a few Oracle databases. On each machine we have 2 shell scripts to run the backups. The TSM scheduler calls a script which calls a different backup script for each DB on the machine.

The problem is if I create an array of SIDs and create a loop through the SIDs the backup fails.



declare -a SIDS=('SID1' 'SID2' 'SID3')
su - oracle

for SID in ${SIDS[@]}
  export ORACLE_HOME='/u01/app/oracle/product/'
  . /usr/local/bin/oraenv
  /usr/local/adm/backup-incrn.sh $LEVEL $SID 35

There is no error in the Logs on the TSM server and it is almost as if the scripts is never called. The logs that are on the machine are not updated with any error messages.

If I use this syntax the backups work perfectly

su - oracle -c "/usr/local/adm/backup-incrn.sh $LEVEL SID1 35"

su - oracle -c "/usr/local/adm/backup-incrn.sh $LEVEL SID2 35"

I think this has to be an error in my script, some variable not being set properly.

Can anyone see the obvious mistake I've made and point it out to me?


  • I would like to know why this was migrated. The problem was that the shell script was not correct, although the shell script was used for database administration.
    – Gisli
    Jan 2, 2013 at 16:12

2 Answers 2

"su - oracle" is the culprit

Remove that line from the script. You can switch the user before you actually run the script. if you switch user in shell script, then it gives you new shell environment loosing further shell instructions. (there are other ways to do it)

  • I have to set the user to oracle in the script. I don't have control over anything else than the script.
    – Gisli
    Dec 28, 2012 at 22:00
  • 1
    then you need to do: "su - oracle -c '<all your shell statements>'"
    – Icarus3
    Dec 28, 2012 at 22:03
  • I think this does the trick. Once I have confirmed that the backups run I will mark this as the answer and post the modified script.
    – Gisli
    Dec 28, 2012 at 23:11

I would guess that because you're issuing a login your declaration of SIDS is not transferred to the shell started by the su command. You can test this by checking the value of SIDS after you issue the "su - oracle"

  • So if I move the su - oracle to the top, the script would work?
    – Gisli
    Dec 28, 2012 at 21:58
  • I think it should work. Try it and see. You don't even need to actually run the backup stuff to examine the environment variables.
    – DCookie
    Dec 28, 2012 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.