Different behaviour

Different behaviour

am 07.07.2011 11:42:05 von HACKER Nora

------_=_NextPart_001_01CC3C8A.21AB0540
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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 { =20
#[... 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 =3D 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 =3D ( caller 0 )[$CALLER_ID];
DEBUG("$fnc - DBType: $dbtype\n");
my $vdb =3D $empty;
my $adb =3D $empty;
if ( $dbtype eq 'V' ) { # in my case FALSE, ignore
# viaMG-DB temporär umspeichern, um Version aus ApplDB =
ermitteln zu können
$vdb =3D $db;
DEBUG("$fnc - viaMG-DB: $vdb\n");
print 'Bitte zugehörige Applikations-DB angeben: ';
INFO("$fnc - Bitte zugehörige Applikations-DB angeben: ");
$adb =3D ;
chomp $adb;
$db =3D $adb;
INFO("$fnc - DB: $db\n");

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

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

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

$dbvers =3D $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 =3D giveDBVersion();
}

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

# SID setzen
$ENV{'ORACLE_SID'} =3D "$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 ) =3D @_;
my $fnc =3D ( 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 =3D `ps -ef |grep -v grep |grep dbw |grep $db`; # =
print grepped ps list for debugging
print "Test: $test\n";
$status =3D $? >> $SHIFT_ERROR;
if ( $status == 0 ) {
INFO("$fnc - DB-Status: $status =3D DB $db is running\n");
} else {
INFO("$fnc - DB-Status: $status =3D DB $db is not =
running\n");
}
} elsif ( $art eq 'T' ) {
system "ps -ef |grep -v grep |grep -w BBL |grep -wq $tux";
$status =3D $? >> $SHIFT_ERROR;
if ( $status == 0 ) {
INFO("$fnc - Tuxedo-Status: $status =3D Tuxedo $tux is =
running\n");
} else {
INFO("$fnc - Tuxedo-Status: $status =3D 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,=20
Nora=20




------_=_NextPart_001_01CC3C8A.21AB0540--

Re: Different behaviour

am 07.07.2011 12:23:56 von Rob Coops

--00163646dad87a6c7104a7781eba
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Thu, Jul 7, 2011 at 11:42 AM, HACKER Nora wrote:

> 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 gre=
ps
> 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 runni=
ng
> or not) both times, on AIX6.1 I get "process running" at the first call o=
f
> 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 =3D 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 D=
B
> sub getDBVersion {
> my $fnc =3D ( caller 0 )[$CALLER_ID];
> DEBUG("$fnc - DBType: $dbtype\n");
> my $vdb =3D $empty;
> my $adb =3D $empty;
> if ( $dbtype eq 'V' ) { # in my case FALSE, ignore
> # viaMG-DB temporär umspeichern, um Version aus ApplDB ermitt=
eln zu
> können
> $vdb =3D $db;
> DEBUG("$fnc - viaMG-DB: $vdb\n");
> print 'Bitte zugehörige Applikations-DB angeben: ';
> INFO("$fnc - Bitte zugehörige Applikations-DB angeben: ");
> $adb =3D ;
> chomp $adb;
> $db =3D $adb;
> INFO("$fnc - DB: $db\n");
>
> # SID setzen
> $ENV{'ORACLE_SID'} =3D "$db";
> INFO("$fnc - ORACLE_SID: $ENV{'ORACLE_SID'}\n");
> }
>
> my $status =3D checkStatus('D'); # <-- this FAILS at the second
> execution :-(
> DEBUG("$fnc - DBStatus aus Unterfunktion checkStatus: $status\n");
>
> my $dbvers;
> if ( $status == 0 ) {
> my $dbverslst =3D "$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 =3D giveDBVersion();
> } else {
> DEBUG("$fnc - Kein Error aus get_db_version.sql.\n");
> }
> my @dbversgrep;
> my $fh_dbverslst =3D IO::File->new("< $dbverslst");
> if ( ! $fh_dbverslst ) {
> LOGDIE("$fnc - $dbverslst konnte nicht gelesen werden!\n");
> }
> while (<$fh_dbverslst>) {
> chomp;
> $_ =3D~ s/ //g;
> if (/[\d.]/s) { push @dbversgrep, $_ }
> }
> undef $fh_dbverslst;
>
> $dbvers =3D $dbversgrep[0];
> INFO("$fnc - Datenbank-Version (aus DB): $dbvers\n");
> if ( -e "$dbverslst" ) {
> unlink $dbverslst
> or INFO(
> "$fnc - Datei $dbverslst konnte nicht gelöscht werd=
en:
> $!\n");
> }
> } else {
> INFO( "$fnc - Datenbank $db ist down.\n" );
> print "Datenbank $db ist down.\n";
> $dbvers =3D giveDBVersion();
> }
>
> if ( $dbtype eq 'V' ) {
> $db =3D $vdb; # viaMG-DB wieder als Haupt-DB einsetzen
>
> # SID setzen
> $ENV{'ORACLE_SID'} =3D "$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 ) =3D @_;
> my $fnc =3D ( 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 =3D `ps -ef |grep -v grep |grep dbw |grep $db`; # print
> grepped ps list for debugging
> print "Test: $test\n";
> $status =3D $? >> $SHIFT_ERROR;
> if ( $status == 0 ) {
> INFO("$fnc - DB-Status: $status =3D DB $db is running\n");
> } else {
> INFO("$fnc - DB-Status: $status =3D DB $db is not running\n");
> }
> } elsif ( $art eq 'T' ) {
> system "ps -ef |grep -v grep |grep -w BBL |grep -wq $tux";
> $status =3D $? >> $SHIFT_ERROR;
> if ( $status == 0 ) {
> INFO("$fnc - Tuxedo-Status: $status =3D Tuxedo $tux is
> running\n");
> } else {
> INFO("$fnc - Tuxedo-Status: $status =3D 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
>
>
>
>
So to make things really simple you basically make the following call: *sys=
tem
"ps -ef |grep -v grep |grep dbw |grep -q $db";* twice the first time you ge=
t
the list as expected the second time you get a -1 from the OS. Would it be
possible to capture more then just the -1 there should (at least usually)
also be a error message in human readable format... that might provide you
with a bit more insight into what the reason is that the OS doesn't like yo=
u
asking twice.

Personally I would simply to test repeat the call 10 times or so so that in
both cases it is executed 10 times. If the first 10 all working without an
issue and the second round throws errors then it certainly is not an OS
issue but it must be that something else (on the OS level?) has changed in
the mean time. ps is a very basic command and I cannot imagine what it migh=
t
be that would cause that to trow an error, the grep command might but only
of if that $db variable is very strange. You might want to try and print it
before and after you make the actual system call just to make sure that it
does not "magically" change which looking at your code it should not but
then again the system call should not fail...

But as you can see above I have no idea why this script might be behaving a=
s
weird as it does. I do suspect that something OS related is the cause of th=
e
weirdness but having never even logged in to an AIX machine I can only
guess...

Regards,

Rob

--00163646dad87a6c7104a7781eba--

AW: Different behaviour

am 07.07.2011 12:50:51 von HACKER Nora

------_=_NextPart_001_01CC3C93.BCE252AA
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: base64

SGkgUm9iLA0KDQpUaGFua3MgZm9yIHlvdXIgcmVwbHkgYW5kIHlvdXIgc3Vn Z2VzdGlvbnMuDQoN
CglTbyB0byBtYWtlIHRoaW5ncyByZWFsbHkgc2ltcGxlIHlvdSBiYXNpY2Fs bHkgbWFrZSB0aGUg
Zm9sbG93aW5nIGNhbGw6IHN5c3RlbSAicHMgLWVmIHxncmVwIC12IGdyZXAg fGdyZXA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b2RlOiAwDQpSZXR1cm4gY29kZTogMA0KUmV0dXJuIGNvZGU6 IDANClJldHVybiBj
b2RlOiAwDQpSZXR1cm4gY29kZTogMA0KU3RhdHVzOiAwDQpEQiBNVlJTVERC IGlzIHJ1bm5pbmcN
Cg0KREI6IE1WUlNUREINClJldHVybiBjb2RlOiAtMQ0KUmV0dXJuIGNvZGU6 IC0xDQpSZXR1cm4g
Y29kZTogLTENClJldHVybiBjb2RlOiAtMQ0KUmV0dXJuIGNvZGU6IC0xDQpS ZXR1cm4gY29kZTog
LTENClJldHVybiBjb2RlOiAtMQ0KUmV0dXJuIGNvZGU6IC0xDQpSZXR1cm4g Y29kZTogLTENClJl
dHVybiBjb2RlOiAtMQ0KU3RhdHVzOiAxNjc3NzIxNQ0KREIgTVZSU1REQiBp cyBub3QgcnVubmlu
Zw0KCQ0KCUJ1dCBhcyB5b3UgY2FuIHNlZSBhYm92ZSBJIGhhdmUgbm8gaWRl YSB3aHkgdGhpcyBz
Y3JpcHQgbWlnaHQgYmUgYmVoYXZpbmcgYXMgd2VpcmQgYXMgaXQgZG9lcy4g SSBkbyBzdXNwZWN0
IHRoYXQgc29tZXRoaW5nIE9TIHJlbGF0ZWQgaXMgdGhlIGNhdXNlIG9mIHRo ZSB3ZWlyZG5lc3Mg
YnV0IGhhdmluZyBuZXZlciBldmVuIGxvZ2dlZCBpbiB0byBhbiBBSVggbWFj aGluZSBJIGNhbiBv
bmx5IGd1ZXNzLi4uDQoNCk5ldmVydGhlbGVzcyB0aGFua3MgZm9yIHlvdXIg ZWZmb3J0IDotKQ0K
DQpDaGVlcnMsDQpOb3JhDQo=

------_=_NextPart_001_01CC3C93.BCE252AA--

Re: Different behaviour

am 07.07.2011 13:24:52 von Rob Coops

--0016e651378a65293a04a778f8d9
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Thu, Jul 7, 2011 at 12:50 PM, HACKER Nora wrote:

> **
>
> Hi Rob,
>
> Thanks for your reply and your suggestions.
>
> So to make things really simple you basically make the following call:
> ***system "ps -ef |grep -v grep |grep dbw |grep -q $db";* twice the
> first time you get the list as expected the second time you get a -1 f=
rom
> the OS. Would it be possible to capture more then just the -1 there
> should (at least usually) also be a error message in human readable
> format... that might provide you with a bit more insight into what the
> reason is that the OS doesn't like you asking twice.
>
>
> Normally, the OS errors in text format are also printed on the command
> line, so I guess there is nothing more to display â€=A6!?
>
>
> Personally I would simply to test repeat the call 10 times or so so
> that in both cases it is executed 10 times. If the first 10 all workin=
g
> without an issue and the second round throws errors then it certainly =
is not
> an OS issue but it must be that something else (on the OS level?) has
> changed in the mean time. ps is a very basic command and I cannot imag=
ine
> what it might be that would cause that to trow an error, the grep comm=
and
> might but only of if that $db variable is very strange. You might want=
to
> try and print it before and after you make the actual system call just=
to
> make sure that it does not "magically" change which looking at your co=
de it
> should not but then again the system call should not fail...
>
> Tried it, and the result is as follows â€=93 10 times ok for the fir=
st round,
> 10 errors for the second round. I also checked the $db variable, followin=
g
> your suggestion, and it is set identically both times:
>
> Default-Tuxedo: mvrst
>
> DB: MVRSTDB
>
> Return code: 0
>
> Return code: 0
>
> Return code: 0
>
> Return code: 0
>
> Return code: 0
>
> Return code: 0
>
> Return code: 0
>
> Return code: 0
>
> Return code: 0
>
> Return code: 0
>
> Status: 0
>
> DB MVRSTDB is running
>
> DB: MVRSTDB
>
> Return code: -1
>
> Return code: -1
>
> Return code: -1
>
> Return code: -1
>
> Return code: -1
>
> Return code: -1
>
> Return code: -1
>
> Return code: -1
>
> Return code: -1
>
> Return code: -1
>
> Status: 16777215
>
> DB MVRSTDB is not running
>
> But as you can see above I have no idea why this script might be
> behaving as weird as it does. I do suspect that something OS related i=
s
> the cause of the weirdness but having never even logged in to an AIX m=
achine
> I can only guess...
>
> Nevertheless thanks for your effort J
>
> Cheers,
>
> Nora
>
I guess that is clear then there is a definite change between the first and
the second attempt at this system call. The first time no mater how often
you all it you get the same result over and over again. The second time you
always get a return code -1. So it is the OS that for what ever reason sees
the second request as something quite different then the first...
I assume you have compared both out puts from: my $test =3D `ps -ef |grep -=
v
grep |grep dbw |grep $db`; # print grepped ps list for debugging and foun=
d
no difference there? You can in both cases execute this on the command line
without issues...

Try making a different system call like 'echo "Hello world' or something
that simple just to see if this does the same and fails on the second try
(it should) if it does I would have to say that your OS does not like your
program running the same system call more then once (for what ever reason)

Now if this was Solaris I would suggest a simple process trace to see
exactly what the OS was seeing in terms of requests and what it was doing t=
o
cause it to choke on the second one. I don't know if this is possible on AI=
X
if it is this would be the best option to figure it out. Lacking a tool lik=
e
that I fear that I am at a loss as to how to even try and figure this one
out.

The Solaris process trace or ptrace as the tool is called allows you to see
every call made on the OS level (open file, read memory, access port etc...=
)
it allows you providing that you use more or push the output to a file to
see exactly what a process is doing and why it is waiting, or failing to
execute a certain call. It has helped me several times to find things like
locks on files (also system files) due to other processes creating exclusiv=
e
locks (seemingly random error explained) or issues with libraries that wher=
e
so far down the dependency chain that no one even knew they where ever bein=
g
called.

Regards,

Rob

--0016e651378a65293a04a778f8d9--

Re: Different behaviour

am 07.07.2011 15:44:56 von Rob Dixon

On 07/07/2011 10:42, HACKER Nora wrote:
> 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 i=
s
> 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 scrip=
t
> this function is called twice. On AIX5.3, I get the same result (proces=
s
> 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 a=
n
> 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 =3D 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 =3D ( caller 0 )[$CALLER_ID];
> DEBUG("$fnc - DBType: $dbtype\n");
> my $vdb =3D $empty;
> my $adb =3D $empty;
> if ( $dbtype eq 'V' ) { # in my case FALSE, ignore
> # viaMG-DB temporär umspeichern, um Version aus ApplDB ermit=
teln zu können
> $vdb =3D $db;
> DEBUG("$fnc - viaMG-DB: $vdb\n");
> print 'Bitte zugehörige Applikations-DB angeben: ';
> INFO("$fnc - Bitte zugehörige Applikations-DB angeben: ");
> $adb =3D;
> chomp $adb;
> $db =3D $adb;
> INFO("$fnc - DB: $db\n");
>
> # SID setzen
> $ENV{'ORACLE_SID'} =3D "$db";
> INFO("$fnc - ORACLE_SID: $ENV{'ORACLE_SID'}\n");
> }
>
> my $status =3D checkStatus('D'); #<-- this FAILS at the second=
execution :-(
> DEBUG("$fnc - DBStatus aus Unterfunktion checkStatus: $status\n");
>
> my $dbvers;
> if ( $status == 0 ) {
> my $dbverslst =3D "$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 =3D giveDBVersion();
> } else {
> DEBUG("$fnc - Kein Error aus get_db_version.sql.\n");
> }
> my @dbversgrep;
> my $fh_dbverslst =3D IO::File->new("< $dbverslst");
> if ( ! $fh_dbverslst ) {
> LOGDIE("$fnc - $dbverslst konnte nicht gelesen werden!\n")=
;
> }
> while (<$fh_dbverslst>) {
> chomp;
> $_ =3D~ s/ //g;
> if (/[\d.]/s) { push @dbversgrep, $_ }
> }
> undef $fh_dbverslst;
>
> $dbvers =3D $dbversgrep[0];
> INFO("$fnc - Datenbank-Version (aus DB): $dbvers\n");
> if ( -e "$dbverslst" ) {
> unlink $dbverslst
> or INFO(
> "$fnc - Datei $dbverslst konnte nicht gelöscht wer=
den: $!\n");
> }
> } else {
> INFO( "$fnc - Datenbank $db ist down.\n" );
> print "Datenbank $db ist down.\n";
> $dbvers =3D giveDBVersion();
> }
>
> if ( $dbtype eq 'V' ) {
> $db =3D $vdb; # viaMG-DB wieder als Haupt-DB einsetzen
>
> # SID setzen
> $ENV{'ORACLE_SID'} =3D "$db";
> INFO("$fnc - ORACLE_SID: $ENV{'ORACLE_SID'}\n");
>
> }
>
> return $dbvers;
>
> }
>
> #################
> # This is the sub-function for checking whether the Oracle DB (and/or T=
uxedo) is running
> sub checkStatus {
> my ( $art ) =3D @_;
> my $fnc =3D ( 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 =3D `ps -ef |grep -v grep |grep dbw |grep $db`; # p=
rint grepped ps list for debugging
> print "Test: $test\n";
> $status =3D $?>> $SHIFT_ERROR;
> if ( $status == 0 ) {
> INFO("$fnc - DB-Status: $status =3D DB $db is running\n");
> } else {
> INFO("$fnc - DB-Status: $status =3D DB $db is not running\=
n");
> }
> } elsif ( $art eq 'T' ) {
> system "ps -ef |grep -v grep |grep -w BBL |grep -wq $tux";
> $status =3D $?>> $SHIFT_ERROR;
> if ( $status == 0 ) {
> INFO("$fnc - Tuxedo-Status: $status =3D Tuxedo $tux is run=
ning\n");
> } else {
> INFO("$fnc - Tuxedo-Status: $status =3D Tuxedo $tux is not=
running\n");
> }
> }
>
> return $status;
> }
>
> #################
> # This is the script output with the grepped ps list output for debuggi=
ng 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_MVRST=
DB
> 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_MVRST=
DB
> oracle 765990 1 0 08:57:47 - 0:00 ora_dbw0_MVRSTDB
>
> DB MVRSTDB is not running
>
> [...]
>
>
>
>
> Any hints in which direction to investigate???

Hi Nora

First of all, please bottom-post your responses and flag quoted lines
with a prefix (usually "> "). And do you use 'strict' and 'warnings'
as there is a call to 'undef' that shouldn't be necessary.

That is a /lot/ of code to digest and debug, especially without access
to the system you are using.

You should start by reducing the program to something minimal that
displays the same problem. Forget the overall functionality and remove
as much code as you can that is irrelevant to the the problem.

Remember 'divide and conquer' - if you can split the program into two or
more parts that you can run independently then do so, and see if the
fault persists in either.

Also, although I have no idea what appl() does, you should change this li=
ne

appl( 'start', 'D', checkStatus('D') );

to

my $status =3D checkStatus('D');
appl('start', 'D', $status);

so that you can examine the result of checkStatus() independently of the
call to appl().

Finally, from a quick scan it looks like the first call to checkStatus()
is directly from backup(), whereas the second is indirectly via a call
to getDBVersion(). That implies that the latter subroutine is messing
things up, and you should check with what something like

sub test {
checkStatus();
getDBVersion();
}

does.

I hope this helps for now.

Rob


--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Different behaviour

am 08.07.2011 01:01:08 von jwkrahn

HACKER Nora wrote:
> Hello,

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 =3D 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 =3D ( caller 0 )[$CALLER_ID];

Where did $CALLER_ID come from?

> DEBUG("$fnc - DBType: $dbtype\n");

Where did $dbtype come from?

> my $vdb =3D $empty;
> my $adb =3D $empty;

Where did $empty come from? What is $empty supposed to contain?

> if ( $dbtype eq 'V' ) { # in my case FALSE, ignore
> # viaMG-DB temporär umspeichern, um Version aus ApplDB ermit=
teln zu können
> $vdb =3D $db;
> DEBUG("$fnc - viaMG-DB: $vdb\n");
> print 'Bitte zugehörige Applikations-DB angeben: ';
> INFO("$fnc - Bitte zugehörige Applikations-DB angeben: ");
> $adb =3D;
> chomp $adb;
> $db =3D $adb;

Shouldn't that be:

my $db =3D $adb;

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

Why are you copying $db to a string?

> INFO("$fnc - ORACLE_SID: $ENV{'ORACLE_SID'}\n");
> }
>
> my $status =3D checkStatus('D'); #<-- this FAILS at the second=
execution :-(
> DEBUG("$fnc - DBStatus aus Unterfunktion checkStatus: $status\n");
>
> my $dbvers;
> if ( $status == 0 ) {
> my $dbverslst =3D "$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";

You should verify that system() executed correctly.

perldoc -f system

> DEBUG(
> "$fnc - $sqlplus \"/as sysdba\" \@$sqls/get_db_version.sql=
$db\n");
>
> if ( fgrep { /ERROR/ } $dbverslst ) {

The UNIX fgrep utility does not use regular expressions so this is a bit=20
confusing. Why aren't you just using perl's built-in grep() here? And=20
why use grep() at all on a list with only one element?

if ( $dbverslst =3D~ /ERROR/ ) {

> $dbvers =3D giveDBVersion();
> } else {
> DEBUG("$fnc - Kein Error aus get_db_version.sql.\n");
> }
> my @dbversgrep;
> my $fh_dbverslst =3D IO::File->new("< $dbverslst");

You should *always* verify that files opened correctly. Why aren't you=20
just using perl's built-in open() here?

open my $fh_dbverslst, '<', $dbverslst or die "Cannot open=20
'$dbverslst' because: $!";

> if ( ! $fh_dbverslst ) {

That is not the correct way to test a filehandle.

perldoc -f fileno

Or just test the return value of open().

perldoc perlopentut
perldoc -f open

> LOGDIE("$fnc - $dbverslst konnte nicht gelesen werden!\n")=
;
> }
> while (<$fh_dbverslst>) {
> chomp;
> $_ =3D~ s/ //g;

Why "$_ =3D~" here and not below?

> if (/[\d.]/s) { push @dbversgrep, $_ }

The /s option only affects the . special character which you are not usin=
g.

> }
> undef $fh_dbverslst;
>
> $dbvers =3D $dbversgrep[0];
> INFO("$fnc - Datenbank-Version (aus DB): $dbvers\n");
> if ( -e "$dbverslst" ) {

Why are you copying $dbverslst to a string? Why test for (-e) existence=20
when unlink(), through $!, will tell you if $dbverslst doesn't exist?

> unlink $dbverslst
> or INFO(
> "$fnc - Datei $dbverslst konnte nicht gelöscht wer=
den: $!\n");
> }
> } else {
> INFO( "$fnc - Datenbank $db ist down.\n" );
> print "Datenbank $db ist down.\n";
> $dbvers =3D giveDBVersion();
> }
>
> if ( $dbtype eq 'V' ) {
> $db =3D $vdb; # viaMG-DB wieder als Haupt-DB einsetzen
>
> # SID setzen
> $ENV{'ORACLE_SID'} =3D "$db";

Why are you copying $db to a string?

> INFO("$fnc - ORACLE_SID: $ENV{'ORACLE_SID'}\n");
>
> }
>
> return $dbvers;
>
> }
>
> #################
> # This is the sub-function for checking whether the Oracle DB (and/or T=
uxedo) is running
> sub checkStatus {
> my ( $art ) =3D @_;
> my $fnc =3D ( caller 0 )[$CALLER_ID];

Where did $CALLER_ID come from?

> DEBUG("$fnc - Übergabeparameter: @_\n");
>
> my $status;
> if ( $art eq 'D' ) {
> system "ps -ef |grep -v grep |grep dbw |grep -q $db";

Where did $db come from?

> my $test =3D `ps -ef |grep -v grep |grep dbw |grep $db`; # p=
rint grepped ps list for debugging
> print "Test: $test\n";
> $status =3D $?>> $SHIFT_ERROR;

Where did $SHIFT_ERROR come from? You should put this line *directly*=20
*after* the line that sets $?. You are probably getting the status from=20
the shell that the back-ticks run, but print() might affect its value.=20
If you want the status from system() you should only use $? right after=20
system() has completed.

When you use system() you should verify that it executed correctly.

perldoc -f system

> if ( $status == 0 ) {
> INFO("$fnc - DB-Status: $status =3D DB $db is running\n");
> } else {
> INFO("$fnc - DB-Status: $status =3D DB $db is not running\=
n");
> }
> } elsif ( $art eq 'T' ) {
> system "ps -ef |grep -v grep |grep -w BBL |grep -wq $tux";

Where did $tux come from?

> $status =3D $?>> $SHIFT_ERROR;
> if ( $status == 0 ) {
> INFO("$fnc - Tuxedo-Status: $status =3D Tuxedo $tux is run=
ning\n");
> } else {
> INFO("$fnc - Tuxedo-Status: $status =3D Tuxedo $tux is not=
running\n");
> }
> }
>
> return $status;
> }
>
> #################
> # This is the script output with the grepped ps list output for debuggi=
ng 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_MVRST=
DB
> 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_MVRST=
DB
> oracle 765990 1 0 08:57:47 - 0:00 ora_dbw0_MVRSTDB
>
> DB MVRSTDB is not running
>
> [...]
>
>
>
>
> Any hints in which direction to investigate???

Do you have utilities like pgrep on AIX? Does your version of ps=20
support the -o option?

In some shells, instead of doing:

ps -ef | grep -v grep | grep dbw

You can just do:

ps -ef | grep d[b]w




John
--=20
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein

--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/