Hello,

I would be really glad if someone could give me a hint to my following problem: 
I have a script that runs smoothly on AIX5.3, installed Perl is 5.8.8. Now I 
need it to run on AIX6.1, Perl is 5.8.8 as well, but I experience a strange, 
differing behaviour. I have a sub-function that greps for a certain process in 
the ps list. In the course of this script this function is called twice. On 
AIX5.3, I get the same result (process running or not) both times, on AIX6.1 I 
get "process running" at the first call of the sub, but error -1 at the second 
call. Could this be an OS behaviour problem?

Here are the code snippets:

#################
# This is the main function of my script (doing DB backups/restore)
sub backup {  
    #[... some other subs ...]
    appl( 'start', 'D', checkStatus('D') ); # starts the Oracle DB if 
checkStatus returns that DB is not running; gives correct result
    #[... some other subs ...]
    my $dbvers = getDBVersion(); # gets the application version from the DB; on 
AIX6.1 this produces os level error -1
    #[... some other subs ...]
}

#################
# This is the sub-function for getting the application version from the DB
sub getDBVersion {
    my $fnc = ( caller 0 )[$CALLER_ID];
    DEBUG("$fnc - DBType: $dbtype\n");
    my $vdb = $empty;
    my $adb = $empty;
    if ( $dbtype eq 'V' ) {     # in my case FALSE, ignore
        # viaMG-DB temporär umspeichern, um Version aus ApplDB ermitteln zu 
können
        $vdb = $db;
        DEBUG("$fnc - viaMG-DB: $vdb\n");
        print 'Bitte zugehörige Applikations-DB angeben: ';
        INFO("$fnc - Bitte zugehörige Applikations-DB angeben: ");
        $adb = <STDIN>;
        chomp $adb;
        $db = $adb;
        INFO("$fnc - DB: $db\n");

        # SID setzen
        $ENV{'ORACLE_SID'} = "$db";
        INFO("$fnc - ORACLE_SID: $ENV{'ORACLE_SID'}\n");
    }

    my $status = checkStatus('D');     # <-- this FAILS at the second execution 
:-(
    DEBUG("$fnc - DBStatus aus Unterfunktion checkStatus: $status\n");

    my $dbvers;
    if ( $status == 0 ) {
        my $dbverslst = "$tmps/dbversion_$db.lst";
        DEBUG("$fnc - Tempfile mit DB-Version: $dbverslst\n");

        system "$sqlplus"
          . ' "/as sysdba" '
          . "\@$sqls/get_db_version.sql $db > /dev/null 2>&1";
        DEBUG(
            "$fnc - $sqlplus \"/as sysdba\" \@$sqls/get_db_version.sql $db\n");

        if ( fgrep { /ERROR/ } $dbverslst ) {
            $dbvers = giveDBVersion();
        } else {
            DEBUG("$fnc - Kein Error aus get_db_version.sql.\n");
        }
        my @dbversgrep;
        my $fh_dbverslst = IO::File->new("< $dbverslst");
        if ( ! $fh_dbverslst ) {
            LOGDIE("$fnc - $dbverslst konnte nicht gelesen werden!\n");
        }
        while (<$fh_dbverslst>) {
            chomp;
            $_ =~ s/ //g;
            if (/[\d.]/s) { push @dbversgrep, $_ }
        }
        undef $fh_dbverslst;

        $dbvers = $dbversgrep[0];
        INFO("$fnc - Datenbank-Version (aus DB): $dbvers\n");
        if ( -e "$dbverslst" ) {
            unlink $dbverslst
              or INFO(
                  "$fnc - Datei $dbverslst konnte nicht gelöscht werden: $!\n");
        }
    } else {
        INFO( "$fnc - Datenbank $db ist down.\n" );
        print "Datenbank $db ist down.\n";
        $dbvers = giveDBVersion();
    }

    if ( $dbtype eq 'V' ) {
        $db = $vdb; # viaMG-DB wieder als Haupt-DB einsetzen

        # SID setzen
        $ENV{'ORACLE_SID'} = "$db";
        INFO("$fnc - ORACLE_SID: $ENV{'ORACLE_SID'}\n");

    }

    return $dbvers;

}

#################
# This is the sub-function for checking whether the Oracle DB (and/or Tuxedo) 
is running
sub checkStatus {
    my ( $art ) = @_;
    my $fnc = ( caller 0 )[$CALLER_ID];
    DEBUG("$fnc - Übergabeparameter: @_\n");

    my $status;
    if ( $art eq 'D' ) {
        system "ps -ef |grep -v grep |grep dbw |grep -q $db";
        my $test = `ps -ef |grep -v grep |grep dbw |grep $db`;   # print 
grepped ps list for debugging
        print "Test: $test\n";
        $status = $? >> $SHIFT_ERROR;
        if ( $status == 0 ) {
            INFO("$fnc - DB-Status: $status = DB $db is running\n");
        } else {
            INFO("$fnc - DB-Status: $status = DB $db is not running\n");
        }
    } elsif ( $art eq 'T' ) {
        system "ps -ef |grep -v grep |grep -w BBL |grep -wq $tux";
        $status = $? >> $SHIFT_ERROR;
        if ( $status == 0 ) {
            INFO("$fnc - Tuxedo-Status: $status = Tuxedo $tux is running\n");
        } else {
            INFO("$fnc - Tuxedo-Status: $status = Tuxedo $tux is not 
running\n");
        }
    }

    return $status;
}

#################
# This is the script output with the grepped ps list output for debugging 
purposes:

oracle:/opt/magna/wartung> dbmove.pl -m s -d MVRSTDB
Default-Tuxedo: mvrst
Return code: 0
Test:   oracle  299118       1   0 08:57:47      -  0:00 ora_dbw1_MVRSTDB
  oracle  765990       1   0 08:57:47      -  0:00 ora_dbw0_MVRSTDB

DB MVRSTDB is running

Return code: -1
Test:   oracle  299118       1   0 08:57:47      -  0:00 ora_dbw1_MVRSTDB
  oracle  765990       1   0 08:57:47      -  0:00 ora_dbw0_MVRSTDB

DB MVRSTDB is not running

[...]




Any hints in which direction to investigate???

Cheers, 
Nora 



Reply via email to