Help with database checking script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with database checking script
# 1  
Old 06-23-2012
Help with database checking script

I haven't coded in ksh in forever and this script is proving me not a great coder. I keep getting unexpected end of file when I try to execute this...Line 94 is the last line of the code..

#!/usr/bin/ksh
. /home/oraprod/.bash_profile
DBSID=prod # Database sid
CONNECTSTR=apps/xxxxxxxx@prod # Connect string prod
MAILADR=dba@group.com # mail
ACCEPTLAG=2 # allowed difference

# set the environment to the standby database
export ORACLE_SID=prod
export ORACLE_HOME=/u02/app/proddb/10.1.0.5
export PATH=$PATH:$ORACLE_HOME/bin
# declare functions to query v$archived_log and other checks

runsqlstb()
{
sqlplus -S <<EOF
/ as sysdba
set heading off
select max(sequence#) from v\$archived_log where applied='YES' and dest_id=2 ;
exit
#EOF
}

runsqlprd()
{
sqlplus -S ${CONNECTSTR} <<EOF
set heading off
select max(sequence#) from v\$archived_log;
exit
# EOF
}

mailme()
{
if [ ${LAGDIFF} -gt ${ACCEPTLAG} ]
then
echo
echo The ${DBSID} standby database lacks behind too far.
echo logseq ${DBSID} production database is $NUMBERPRD >> mailtempl
echo logseq ${DBSID} standby database is $NUMBERSTB >> mailtempl
echo
mailx -s "Standby database out of sync " ${MAILADR} < mailtempl
rm mailtempl
fi
}

errtrap()
{
#echo Fout in script > mailtempl
mailx -s "Fout in script " ${MAILADR} < mailtempl
rm mailtempl
}
################### MAIN ######################################
NUMBERSTB=`runsqlstb`
if [ $? -ne 0 ]
then
echo "Something wrong with Standbyi" ${DBSID} > mailtempl
errtrap
fi

NUMBERPRD=`runsqlprd`
if [ $? -ne 0 ]
then
echo "Something wrong with" ${DBSID} > mailtempl
errtrap
fi

echo standby database is ${NUMBERSTB}
echo production database is ${NUMBERPRD}

LAGDIFF=`expr ${NUMBERPRD} - ${NUMBERSTB}`
mailme

"standby_monitor2.sh" 93L, 2416C written

[prod@kfc52d : prod ] > ./standby_monitor2.sh
./standby_monitor2.sh: line 94: syntax error: unexpected end of file
# 2  
Old 06-23-2012
Remove "#" from #EOF and # EOF.
# 3  
Old 06-23-2012
Those comments were recent additions to the script...I just uncommented them out and it gives the same error. Thanks
# 4  
Old 06-23-2012
Can you post the most recent version of the script using code tags?
# 5  
Old 06-23-2012
#!/usr/bin/ksh
. /home/oraprod/.bash_profile
DBSID=prod # Database sid
CONNECTSTR=apps/xxxxxx@prod # Connect string prod
#MAILADR=dba@group.com # mail
ACCEPTLAG=2 # allowed difference between standby log and primary log sequence#
# set the environment to the standby database
export ORACLE_SID=prod
export ORACLE_HOME=/u02/app/proddb/10.1.0.5
export PATH=$PATH:$ORACLE_HOME/bin
# declare functions to query v$archived_log and other checks
Code:
runsqlstb()
{
sqlplus -S <<EOF
/ as sysdba
set heading off
select max(sequence#) from v\$archived_log where applied='YES' and dest_id=2 ;
exit
EOF
}

Code:
runsqlprd()
{
    sqlplus -S ${CONNECTSTR} <<EOF
    set heading off
    select max(sequence#) from v\$archived_log;
    exit
    EOF
}

Code:
mailme()
{
if [ ${LAGDIFF} -gt ${ACCEPTLAG} ]
then
    echo
    echo The ${DBSID} standby database lacks behind too far.
    echo logseq ${DBSID} production database is $NUMBERPRD >> mailtempl
    echo logseq ${DBSID} standby database is $NUMBERSTB >> mailtempl
    echo
    mailx -s "Standby database out of sync " ${MAILADR} < mailtempl
    rm mailtempl
fi
}

Code:
errtrap()
{
#echo Fout in script  > mailtempl
mailx -s "Fout in script " ${MAILADR} < mailtempl
rm mailtempl
}

################### MAIN ######################################
NUMBERSTB=`runsqlstb`
if [ $? -ne 0 ]
then
echo "Something wrong with Standbyi" ${DBSID} > mailtempl
errtrap
fi
NUMBERPRD=`runsqlprd`
if [ $? -ne 0 ]
then
echo "Something wrong with" ${DBSID} > mailtempl
errtrap
fi
echo standby database is ${NUMBERSTB}
echo productie database is ${NUMBERPRD}

LAGDIFF=`expr ${NUMBERPRD} - ${NUMBERSTB}`
mailme
# 6  
Old 06-23-2012
Change
Code:
runsqlprd()
{
    sqlplus -S ${CONNECTSTR} <<EOF
    set heading off
    select max(sequence#) from v\$archived_log;
    exit
    EOF
}

to
Code:
runsqlprd()
{
    sqlplus -S ${CONNECTSTR} <<EOF
    set heading off
    select max(sequence#) from v\$archived_log;
    exit
EOF
}

This User Gave Thanks to bartus11 For This Post:
# 7  
Old 06-23-2012
That did the trick...THANKS BARTUS11...I owe you a beer..... :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

2. Shell Programming and Scripting

Shell Script for continuously checking status of a another script running in background, and immedia

Hi, I want to write a script which continuously checking status of a script running in background by nohup command. And if same script is not running then immediately start the script...please help.. i am using below command to run script nohup system_traps.sh & but in some... (9 Replies)
Discussion started by: ketanraut
9 Replies

3. Programming

Dynamically checking rules in database tables using SQL

I want to check for rows in a table where all values (except the key) is empty. I am using MySQL 5.5. I plan to do this mechanically, so the approach should work for any table in my database schema. Suppose for illustration purposes I start with the following table: CREATE TABLE `sources` ( ... (4 Replies)
Discussion started by: figaro
4 Replies

4. Shell Programming and Scripting

Checking for print with script.

Hi! During work as Oracle sysadmin. I need to print output of Oracle report (text mode) without first page. Into this page user has printed parameters of this report. My idea was check number of page breaks by running -> grep -i $'^\f' <file name> | wc -l and send to printer parameter... (1 Reply)
Discussion started by: beckss
1 Replies

5. Shell Programming and Scripting

File checking script need help

Hi, Gurus, I need a scripts to check specified file if it exists or not at certain time (say every month between 5th and 7th). if file exists do something otherwise do another thing. can anybody help this? Thanks in advance :wall: (3 Replies)
Discussion started by: ken002
3 Replies

6. Solaris

Checking RAID health, metastat returns "no database"

Hello, I am supposed to check the RAID health of a system but when I type metastat it says "there are no existing databases" Does this mean that there is no RAID configured at all? Is there any other utility I should try? I know the system has two disks. Tanks! (8 Replies)
Discussion started by: cevspencer
8 Replies

7. Shell Programming and Scripting

Eliminate variable checking in a script

RH Linux, $SHELL=/bin/ksh I have a .profile which I source in as such --> . .profile Whats happening is the variables are getting validated and generating errors. for example .profile export foo=/to/the/moon when I . .profile , I get : not foundmyusername/.profile or bad... (8 Replies)
Discussion started by: BMetelsky
8 Replies

8. Shell Programming and Scripting

Shell Script: want to insert values in database when update script runs

Hi , I am new to linux and also also to shell scripting. I have one shell script which unpacks .tgz file and install software on machine. When this script runs I want to insert id,filename,description(which will be in readme file),log(which will be in log file) and name of unpacked folder... (1 Reply)
Discussion started by: ring
1 Replies

9. UNIX for Dummies Questions & Answers

Script syntax checking

Is it possible to check the script syntax with some sort of command...? Without running the script . I'm using Sun Solaris (3 Replies)
Discussion started by: bjornrud
3 Replies

10. Shell Programming and Scripting

checking for script errors

ok, i have a script which i use to search my process' for specific keywords and kill any process containing them. there is a prompt to enter a keyword for searching and another prompt for which user you want to search the process' of. i want the script to have something that if you entered a search... (1 Reply)
Discussion started by: Blip
1 Replies
Login or Register to Ask a Question