I'm writing a script that does many things, but it runs as a root. It does some backups etc, and then it su's over to oracle user to do some oracle stuff, this way I don't have to worry about Oracle env variables etc. Saves time, headache etc.
The thing is that, this script worked perfectly on Solaris, but it not in Linux (Redhat and Suse).
Here is a snippet:
#!/usr/bin/ksh
## doing some maintenance as root user
tar -cvf /usr/home/dir
...
## Now do some oracle stuff###
SH_LOG=/tmp/script123.log
echo "Enter user name for oracle:"
read $ORA_USER
su - $ORA_USER "sqlplus -S -L / AS SYSDBA <<\EOF >$SH_LOG
SET HEADING OFF;
SELECT GROUP#, BYTES, STATUS FROM V\$LOG;
SPOOL OFF
EXIT;
EOF"
## EOF
This above script works and changes over to oracle user in Solaris, runs my sql commands and gives me a log. When I run it in Linux, it craps out. My guess it that "su -" does not pass the variables in Linux, so it doesn't understand $ORA_USER and $SH_LOG.
I even tried "su - $ORA_USER -c -m" options, they all failed to give me the desired results. Any ideas?
Thanks in advance.
-Nitin