Sunday, July 15, 2007

Shell scripting | Convert system date to Oracle Format.

Here is a small scriptling that basically can be used to get the system date and convert it into Oracle format. This script basically can compare the system date with the date got from Oracle and mail someone whether the comparison was a success or else.

#!/bin/bash
a=`sqlplus -s / b=`date +"%m-%h-%Y"|tr [a-z] [A-Z]` # Obtaining the system date and converting it to Oracle format
if [ "$a" = "$b" ]; # Comparing if the dates are same. This was just the logic I had required in my script. Could be different for you.
then flag=0;
else flag=1;
fi;

if [ "$flag" = 0 ];
then echo "Dates are same. Body of the mail"|mail -s "Subject of the mail" yourname@yoursite.com;
else
echo "Dates are different, Body of the mail"|mail -s "Subject of the mail" yourname@yoursite.com;
fi;

##################END######################
test.sql can be obtained as following. Remember, test.sql could have been made inline with the redirection operator "<<".

SET echo off;
SET pagesize 0;
SET heading off;
select MY_DATE
from MY_TABLE;

No comments: