Reputation: 11
Hi The below script is working fine when executing from the command prompt but it is not giving any result when scheduled in cron. Please help.
#!/bin/bash
db_mode()
{
$ORACLE_HOME/bin/sqlplus -s << eof
system/xxxxx@<DB_NAME>
SET LINES 132
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
select open_mode from v\$database;
exit;
eof
}
state=`db_mode`
echo $state > /home/oracle/dba/scripts/monitor/state.log
Hi all,
I scheduled the job with -l and it seems to have worked. This is how I have scheduled the job now
*/1 * * * * /bin/bash -l /home/oracle/dba/scripts/monitor/db_mode.sh
Earlier I scheduled it as
*/1 * * * * /bin/bash /home/oracle/dba/scripts/monitor/db_mode.sh
Thanks all.
Upvotes: 1
Views: 250
Reputation: 467
Cron will not dump output here and there, as it doesn't run with a "standard input" or "standard output," since it has no "controlling terminal" associated with it. Only I/O to and from specified files will work. Never mind that $ORACLE_JAZZ.
Upvotes: 0
Reputation: 20012
Try sourcing your .bashrc or .profile first:
*/1 * * * * source /home/oracle/.bashrc; /home/oracle/dba/scripts/monitor/db_mode.sh
Upvotes: 0
Reputation: 1424
mostly this variable is not seen by the script when running from cron
$ORACLE_HOME
use the full path and it should work
in general dont depend on any environment variable when running from cron so if sqlplus depend on environment variables you have to set them in the script so that they are seen
the reason for this is that cron is not running from normal shell and it does not have the initialization you get when loggin in to normal shell in .bashrc etc
Upvotes: 1