I need to run a sql statement on a certain time interval on the day. I log in as root and need to change the user to oracle to run the sql statement.
here what's I have:
#!/usr/bin/sh
su - oracle
sqlresult=`sqlplus -s username/pwd <<end
set pagesize 0 feedback off ver off heading off echo off
select something
from something
where some criteria
exit;
end`
echo $sqlresult >>somelog.txt
exit
that supposedly should change the user to oracle, run the sql statement and write the result to the log file. However, it changed the usr to oracle, but didn't run the sql statement.
if I changed the usr to oracle, take "su - oracle" out and and run the script, it worked fine. Why the sqlstatement doesn't get run when su is in the script?
We have the reason not to set a cronjob at 'oracle' user. We want to set it run at the root level.
Thanks
here what's I have:
#!/usr/bin/sh
su - oracle
sqlresult=`sqlplus -s username/pwd <<end
set pagesize 0 feedback off ver off heading off echo off
select something
from something
where some criteria
exit;
end`
echo $sqlresult >>somelog.txt
exit
that supposedly should change the user to oracle, run the sql statement and write the result to the log file. However, it changed the usr to oracle, but didn't run the sql statement.
if I changed the usr to oracle, take "su - oracle" out and and run the script, it worked fine. Why the sqlstatement doesn't get run when su is in the script?
We have the reason not to set a cronjob at 'oracle' user. We want to set it run at the root level.
Thanks