Home » RDBMS Server » Server Administration » sql script on crontab
sql script on crontab [message #145166] Tue, 01 November 2005 07:53 Go to next message
alanm
Messages: 284
Registered: March 2005
Senior Member

hi all,
I have some sql scripts which i run on the crontab. I would ideally like these scripts to send an email. However I am not sure how to pipe the crontab to an email. can anyone help.

best regards

Alan.
Re: sql script on crontab [message #145167 is a reply to message #145166] Tue, 01 November 2005 08:00 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10708
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Schedule the script in your crontab.
oracle@hostname#cat somescript
#/bin/bash
sqlplus -s scott/tiger <<EOF
--include your formatting commands
spool /tmp/script.log
select * from dept;
spool off;
exit;
EOF
mailx -s 'Your Meaninful subject' someone@somewhere.com < /tmp/script.log


Re: sql script on crontab [message #145173 is a reply to message #145166] Tue, 01 November 2005 09:03 Go to previous messageGo to next message
alanm
Messages: 284
Registered: March 2005
Senior Member

Hi,
Thanks for the reply.
I have run the script fron the command line and the script hangs at the mailx command. any idea what could be causing this.

script is

su - oracle <<EOF
cd /home/oracle
. MDEV.ksh
cd /home/oracle/rman_scripts
rman target system/tommy rcvcat rman/rman@rman
run {
allocate channel c1 type 'SBT_TAPE' parms
'ENV=(TDPO_OPTFILE=/usr/tivoli/tsm/client/oracle/bin/tdpo.opt)';
allocate channel c2 type 'SBT_TAPE' parms
'ENV=(TDPO_OPTFILE=/usr/tivoli/tsm/client/oracle/bin/tdpo.opt)';
restore database validate;
}
exit;
EOF
mailx -s 'MDEV_backup_validation' someone@somewhere.co.uk

br

Alan.
Re: sql script on crontab [message #145174 is a reply to message #145173] Tue, 01 November 2005 09:35 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10708
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
The reason it is hanging is
>>mailx -s 'MDEV_backup_validation' someone@somewhere.co.uk
You are missing the message part!.
Either you have to redirect the contents of logfile
mailx -s 'MDEV_backup_validation' someone@somewhere.co.uk < somelogfile.log
or write the contents of the message.
mailx -s 'MDEV_backup_validation' someone@somewhere.co.uk <<EOF
something important enough to email has just occurred
EOF 


and you told
>>I have some sql scripts which i run on the crontab
But you are running RMAN scripts.
For various accumilated (and self paranoical) reasons i dont like this method.
I mean, 'su' from root and calling and oracle script (specifically the RMAN commands).

>>su - oracle <<EOF
>>cd /home/oracle
>>. MDEV.ksh

I would do it something like this ( making use of RMAN command MSGLOG and make it a little more fancier, like checking for any specific errors).
By this , the job results are always emailed to you.
If something fails, you can get paged or whatever.

oracle@hostname#cat somermanscript
export ORACLE_SID=yoursid
export ORACLE_BASE=yourbase
export ORACLE_HOME=yourhome
export NLS_DATE_FORMAT='MON DD YYYY HH24:MI:SS'#
export SERVER=`uname -n`
export DB=yourdatabaseNAME
export MAILLIST="person1@work.com person2@work.com" # your mailing list. one or more persons who get mailed.
export LOG=/the_place_where_you_savethe_logfiles/yourlogfile.log
#
$ORACLE_HOME/bin/rman msglog 'yourlogfile.log' << EOF
connect target / ; #add your target information
connect rcvcat rmut/rmut@rmandb; #your catalog information
run
{
#All you want to do
}
exit;
EOF
#
cd /the_place_where_you_savethe_logfiles
grep "error message stack follows" yourlogfile.log > alert_rman
#
if test -s alert_rman
then
mailx -s "ALERT -> Youraction on $DB somestatus(failed/busted)" $MAILLIST <$LOG
mailx -s "ALERT -> Youraction on $DB somestatus(failed/busted)" somepageraddress@address < alert_rman
else
mailx -s "Status -> $DB operation somestatus " $MAILLIST < $LOG
fi

Re: sql script on crontab [message #145200 is a reply to message #145166] Tue, 01 November 2005 12:21 Go to previous messageGo to next message
alanm
Messages: 284
Registered: March 2005
Senior Member

Hi
Thanks, thats a great help. I will investigate your rman methodology too.


cheers

Re: sql script on crontab [message #145327 is a reply to message #145174] Wed, 02 November 2005 09:41 Go to previous messageGo to next message
Sanjay Bajracharya
Messages: 279
Registered: October 2001
Location: Florida
Senior Member
Mahesh Rajendran wrote on Tue, 01 November 2005 09:35

The reason it is hanging is
>>mailx -s 'MDEV_backup_validation' someone@somewhere.co.uk
You are missing the message part!.
Either you have to redirect the contents of logfile
mailx -s 'MDEV_backup_validation' someone@somewhere.co.uk < somelogfile.log
or write the contents of the message.
mailx -s 'MDEV_backup_validation' someone@somewhere.co.uk <<EOF
something important enough to email has just occurred
EOF 


and you told
>>I have some sql scripts which i run on the crontab
But you are running RMAN scripts.
For various accumilated (and self paranoical) reasons i dont like this method.
I mean, 'su' from root and calling and oracle script (specifically the RMAN commands).

>>su - oracle <<EOF
>>cd /home/oracle
>>. MDEV.ksh

I would do it something like this ( making use of RMAN command MSGLOG and make it a little more fancier, like checking for any specific errors).
By this , the job results are always emailed to you.
If something fails, you can get paged or whatever.

oracle@hostname#cat somermanscript
export ORACLE_SID=yoursid
export ORACLE_BASE=yourbase
export ORACLE_HOME=yourhome
export NLS_DATE_FORMAT='MON DD YYYY HH24:MI:SS'#
export SERVER=`uname -n`
export DB=yourdatabaseNAME
export MAILLIST="person1@work.com person2@work.com" # your mailing list. one or more persons who get mailed.
export LOG=/the_place_where_you_savethe_logfiles/yourlogfile.log
#
$ORACLE_HOME/bin/rman msglog 'yourlogfile.log' << EOF
connect target / ; #add your target information
connect rcvcat rmut/rmut@rmandb; #your catalog information
run
{
#All you want to do
}
exit;
EOF
#
cd /the_place_where_you_savethe_logfiles
grep "error message stack follows" yourlogfile.log > alert_rman
#
if test -s alert_rman
then
mailx -s "ALERT -> Youraction on $DB somestatus(failed/busted)" $MAILLIST <$LOG
mailx -s "ALERT -> Youraction on $DB somestatus(failed/busted)" somepageraddress@address < alert_rman
else
mailx -s "Status -> $DB operation somestatus " $MAILLIST < $LOG
fi




Part where
if test -s alert_rman
then
...
fi

try something like

if [-f alert_rman]
then
...
fi
Re: sql script on crontab [message #149122 is a reply to message #145166] Wed, 30 November 2005 03:29 Go to previous messageGo to next message
alanm
Messages: 284
Registered: March 2005
Senior Member

Hi
got this script working and it alerts on success. I however do not know how to script the fail part.

cd /the_place_where_you_savethe_logfiles
grep "error message stack follows" yourlogfile.log > alert_rman
#
if test -s alert_rman
then
mailx -s "ALERT -> Youraction on $DB somestatus(failed/busted)" $MAILLIST <$LOG
mailx -s "ALERT -> Youraction on $DB somestatus(failed/busted)" somepageraddress@address < alert_rman
else
mailx -s "Status -> $DB operation somestatus " $MAILLIST < $LOG
fi

Do you have a script that I could look at to see how you define your errors? Also is the 'error message stack' comma separated errors ?

any help is really appreciated.

regards

Alan.
Re: sql script on crontab [message #149151 is a reply to message #149122] Wed, 30 November 2005 06:32 Go to previous message
Mahesh Rajendran
Messages: 10708
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Quote:

error message stack follows

Is a generic messesage preceded by any RMAN error.
So for all other purposes you can grep through the group of errors or particular errors you are intrested in.
like EXP* or ORA*.
Try to simulate a error and see whether the script alerts you in case of failure.
And If this a backup / recovery log,i always ( self instigated policy!!Smile ) check them manually again.

Previous Topic: Partition Table-needed to set any Initialization Parameters?
Next Topic: Import with statistics
Goto Forum:
  


Current Time: Sat Jan 25 09:53:29 CST 2025