Code works sometimes and sometimes not


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Code works sometimes and sometimes not
# 1  
Old 04-06-2006
Code works sometimes and sometimes not

The following script works sometimes and sometimes not. I am not able to troubleshoot what the problem is ?
Code:
cd ~
. $HOME/.profile

# Orasid.lst has the DB name which I want to Monitor
# Oratab has all the database names on the srver

cat $ORA_SCRIPT/orasid.lst | while read LINE1
do
  cat /etc/oratab | while read LINE
  do
  case $LINE in
  \#*)            ;;      #comment-line in oratab
  *)
  #       Proceed only if third field is 'Y'.
 if [ "`echo $LINE | awk -F: '{print $1}' -`" = $LINE1 ] ; then
 export ORACLE_SID=$LINE1
 export ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`

#
# CHECK FOR ALL DB if Up/Down
#

  if [ -f $ORA_LOG/pmon_process_exist.txt ] ; then /bin/rm $ORA_LOG/pmon_process_exist.txt; fi
  ps -ef | grep ora_pmon_$ORACLE_SID | grep -v grep  > $ORA_LOG/pmon_process_exist.txt
  if [ -s $ORA_LOG/pmon_process_exist.txt ]
  then
        if [ -f $ORA_SCRIPT/select.lst ] ; then /bin/rm $ORA_SCRIPT/select.lst; fi
        $ORACLE_HOME/bin/sqlplus -s ora_connect/ora_connect@$ORACLE_SID @$ORA_SCRIPT/select.sql
        if [ -s $ORA_SCRIPT/select.lst ]
        then
                echo "DB ALL OK"
        else
        for dba in `cat $ORA_SCRIPT/DBA_EMAIL_LIST`
        do
                /usr/bin/mailx -s "PMON is up but DATABASE HAS CONNECTIVITY ISSUES: $ORACLE_SID" $dba < /dev/null
        done
        fi
  else
    for dba in `cat $ORA_SCRIPT/DBA_EMAIL_LIST`
    do
        /usr/bin/mailx -s "DATABASE IS DOWN: $ORACLE_SID" $dba < /dev/null
    done
  rm $ORA_LOG/pmon_process_exist.txt
  fi
 fi
esac
done
done

Can someone tell me why even if the file "$ORA_LOG/pmon_process_exist.txt" exist the code goes to the else stmt (only few times not always).

Code:
if [ -s $ORA_LOG/pmon_process_exist.txt ]
  then
        if [ -s $ORA_SCRIPT/select.lst ]
        then
                echo "DB ALL OK"
        else
        for dba in `cat $ORA_SCRIPT/DBA_EMAIL_LIST`
        do
                /usr/bin/mailx -s "PMON is up but DATABASE HAS CONNECTIVITY ISSUES: $ORACLE_SID" $dba < /dev/null
        done
        fi
else
    for dba in `cat $ORA_SCRIPT/DBA_EMAIL_LIST`
    do
        /usr/bin/mailx -s "DATABASE IS DOWN: $ORACLE_SID" $dba < /dev/null
    done
  rm $ORA_LOG/pmon_process_exist.txt
  fi

So I get an email only 2 or 3 times out of 20 times it runs as a cronjob.
Even if
"ps -ef | grep ora_pmon_$ORACLE_SID | grep -v grep > $ORA_LOG/pmon_process_exist.txt" generates the file.
# 2  
Old 04-06-2006
Also could someone tell me the different
between
if [ -s $ORA_LOG/pmon_process_exist.txt ]
and
if [ -f $ORA_LOG/pmon_process_exist.txt ]
# 3  
Old 04-06-2006
Quote:
Originally Posted by hp-aix-lnx-user
Also could someone tell me the different
between
if [ -s $ORA_LOG/pmon_process_exist.txt ]
and
if [ -f $ORA_LOG/pmon_process_exist.txt ]
'man test'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How the below command works?

hi, can any one explain the below command. run it and see and if you understand please tell me. File=s1_abc.txt.xls.pdf MOD_File=$(echo ${File%.*}_`date +%Y%m%d_%H%M%S%N`.${File##*.}) i asked somedays before and got the above code. i needed to add date time stamp just before the last... (2 Replies)
Discussion started by: Little
2 Replies

2. Shell Programming and Scripting

How does a if works in shell

Hi, I need to compare and get an output for values greater than "X10" (values contain both characters and numbers) using if loop... FOR EG: I want to export values greater than X10, i.e., in-case if the value is X11 and greater than the "if" part to be executed if the value is X9 and... (2 Replies)
Discussion started by: shivashankar_S
2 Replies

3. UNIX for Advanced & Expert Users

How this works?

I have a program............ #include<stdio.h> #include<unistd.h> main() { if(fork == 0) { printf("Hi every body:p!!!!!!!!!!"); } } This program works with out any error. here fork is not a system call. It just act as a variable.But how it works without declaring it? What data type it... (19 Replies)
Discussion started by: carolsanjeevi
19 Replies

4. Shell Programming and Scripting

This code works in the command line but not in a shl script

When I run this code from the command line works spinel.middlebury.edu:/u02/sct/banner/bandev2/middlebury/shl:DEV2$ ls ef* eftseq.dat spinel.middlebury.edu:/u02/sct/banner/bandev2/middlebury/shl:DEV2$ file_seq=$( < eftseq.dat) ... (1 Reply)
Discussion started by: rechever
1 Replies

5. UNIX for Dummies Questions & Answers

>./a.pl works, >a.pl - does not

When I try to execute script, I get message: >aa.pl zsh: command not found: aa.pl but >./aa.pl works OK. What to change in environment to force the former way to work? Thank you, Alex Z (4 Replies)
Discussion started by: zzol
4 Replies

6. Programming

how this works?

pls explain me how this works.... DECODE (SUBSTR (field, 1, 1),'''', '''''' || field || '''','''' || field || '''') here field is a column in an oracle table.... (7 Replies)
Discussion started by: vijay_0209
7 Replies

7. Shell Programming and Scripting

Still trying to get a grep -c that works

I am trying to get a count of each line sub runit2 { my ($file1a, $file2a) = @_; my $file1_vala = $file1a->get; my $file2_vala = $file2a->get; open (FILE1a, "$file1_vala") or die; open (FILE2a, "$file2_vala") or die; chomp(my @strings = <FILE2a>); while (1) { foreach $pattern... (4 Replies)
Discussion started by: popeye
4 Replies

8. UNIX for Dummies Questions & Answers

How ls | wc -l works?

ls displays files in tabbed output. Say a directory contains 3 files. ls will list all 3 in one line. So, I expect ls | wc -l to give 1, but it counts the nr of files and gives 3. Can someone explain how this works? (3 Replies)
Discussion started by: krishmaths
3 Replies

9. Linux

How does NORET_TYPE works ?

Hi, I was looking at the panic() code in linux kernel which is defined as: 51 /** 52 * panic - halt the system 53 * @fmt: The text string to print 54 * 55 * Display a message, then perform cleanups. 56 * 57 * This function never returns. 58 */ 59 60 NORET_TYPE void panic(const char *... (1 Reply)
Discussion started by: amit4g
1 Replies

10. UNIX for Dummies Questions & Answers

How the for loop works?

Hi, I have a landing area where some files keep on coming after irregular intervals of time. From this landing area, I need to move files to another directory for processing. For this, I am using a for loop to find certain kinds of files in the landing area. Now my question is, suppose I start... (6 Replies)
Discussion started by: neelaksh
6 Replies
Login or Register to Ask a Question