Script does not want to run in background ?!?

B

Benoit Lefebvre

I made a little script that ssh to many servers (IBM HMCs) to get a
list of all logical partitions on some pSeries servers managed by the
HMCs

Here is the complete script: (It's called getlpars.pl)
-----------------------------------------------------------------------------------------------------------
#!/usr/bin/perl

chomp(@hmclist = `cat ~/scripts/conf/hmc.list`);

foreach (@hmclist) {
my($hmc,$hmctype) = split(":",$_);

if ($hmctype eq "p4") {

chomp(@list = `ssh -q hscroot\@$hmc 'lssyscfg -r sys --all'`);

@managedsystems = ();

for ($i = 1; $i <= scalar @list -1; $i++) {
$system = substr($list[$i],0,16);
$system =~ s/\s*$//g;
push(@managedsystems, $system);
}

foreach (@managedsystems) {
$system = $_;
$system = "\"".$system."\"";

chomp(@list = `ssh -q hscroot\@$hmc 'lssyscfg -m $system -r lpar
--all'`);

for ($i = 2; $i <= scalar @list -1; $i++) {
$lpar = substr($list[$i],0,20);
$lpar =~ s/\s*$//g;
print $hmc .":". $system .":". $lpar . "\n";
}
}
} elsif ($hmctype eq "p5") {
@list = `ssh -q hscroot\@$hmc 'lssyscfg -r sys'`;

@managedsystems = ();

foreach (@list) {
@ln = split(",", $_);
push(@managedsystems, substr($ln[0],5,length($ln[0])));
}

foreach (@managedsystems) {
$system = $_;
$system =~ s/\s/\\ /g;
@list2 = `ssh -q hscroot\@$hmc 'lssyscfg -r lpar -m $system -F --
header`;
foreach (@list2) {
@ln2 = split(",", $_);
print $hmc .":". $system .":". $ln2[0] . "\n";
}
}
}
}
-----------------------------------------------------------------------------------------------------------

~/scripts/conf/hmc.list contains a list of all HMCs with they type (p4
or p5) delemited with ":"

Content of hmc.list
-----------------------------------------------------------------------------------------------------------
name_of_hmc:p4
name_of_hmc2:p5
-----------------------------------------------------------------------------------------------------------

Here is the "problem"

When I execute the script manually from the shell I get the outputs I
want.

When I run it from the crontab or in background "&" it fails.

[user@server (~/scripts/scripts)]: ./getlpars.pl &
[2] 467196
[2] + Stopped (SIGTTIN) ./getlpars.pl &

Is there any way to get more details on the error.. why it's
stopping ?

Thanks,
--Benoit Lefebvre
(e-mail address removed)
 
B

Bill H

I made a little script that ssh to many servers (IBM HMCs) to get a
list of all logical partitions on some pSeries servers managed by the
HMCs

Here is the complete script: (It's called getlpars.pl)
---------------------------------------------------------------------------­--------------------------------
#!/usr/bin/perl

chomp(@hmclist = `cat ~/scripts/conf/hmc.list`);

foreach (@hmclist) {
my($hmc,$hmctype) = split(":",$_);

if ($hmctype eq "p4") {

chomp(@list = `ssh -q hscroot\@$hmc 'lssyscfg -r sys --all'`);

@managedsystems = ();

for ($i = 1; $i <= scalar @list -1; $i++) {
$system = substr($list[$i],0,16);
$system =~ s/\s*$//g;
push(@managedsystems, $system);
}

foreach (@managedsystems) {
$system = $_;
$system = "\"".$system."\"";

chomp(@list = `ssh -q hscroot\@$hmc 'lssyscfg -m $system -r lpar
--all'`);

for ($i = 2; $i <= scalar @list -1; $i++) {
$lpar = substr($list[$i],0,20);
$lpar =~ s/\s*$//g;
print $hmc .":". $system .":". $lpar . "\n";
}
}
} elsif ($hmctype eq "p5") {
@list = `ssh -q hscroot\@$hmc 'lssyscfg -r sys'`;

@managedsystems = ();

foreach (@list) {
@ln = split(",", $_);
push(@managedsystems, substr($ln[0],5,length($ln[0])));
}

foreach (@managedsystems) {
$system = $_;
$system =~ s/\s/\\ /g;
@list2 = `ssh -q hscroot\@$hmc 'lssyscfg -r lpar -m $system -F --
header`;
foreach (@list2) {
@ln2 = split(",", $_);
print $hmc .":". $system .":". $ln2[0] . "\n";
}
}
}}

---------------------------------------------------------------------------­--------------------------------

~/scripts/conf/hmc.list contains a list of all HMCs with they type (p4
or p5) delemited with ":"

Content of hmc.list
---------------------------------------------------------------------------­--------------------------------
name_of_hmc:p4
name_of_hmc2:p5
---------------------------------------------------------------------------­--------------------------------

Here is the "problem"

When I execute the script manually from the shell I get the outputs I
want.

When I run it from the crontab or in background "&" it fails.

[user@server (~/scripts/scripts)]: ./getlpars.pl &
[2] 467196
[2] + Stopped (SIGTTIN) ./getlpars.pl &

Is there any way to get more details on the error.. why it's
stopping ?

Thanks,
--Benoit Lefebvre
(e-mail address removed)

Could it be a permissions issue? I had a similar issue with a program
that ran fine on a server from the telnet prompt, but wouldnt in a
cronjob. Worked out I had to "chown" it so it would execute in the
cron job.

Bill H
 
B

Benoit Lefebvre

You're supposed to use `ssh -n` for that.

-n Redirects stdin from /dev/null (actually, prevents reading from
stdin). This must be used when ssh is run in the background.

Oh!

Hey it's working now :)

Thanks for that.. I feel so stupid to have forgot that !

Thanks!

--Benoit Lefebvre
(e-mail address removed)
 
J

John W. Krahn

Benoit said:
I made a little script that ssh to many servers (IBM HMCs) to get a
list of all logical partitions on some pSeries servers managed by the
HMCs

Here is the complete script: (It's called getlpars.pl)

use warnings;
use strict;
chomp(@hmclist = `cat ~/scripts/conf/hmc.list`);

foreach (@hmclist) {

Why fork a shell to cat a file when you can just open it in perl?

open HMCLIST, '<', "$ENV{HOME}/scripts/conf/hmc.list"
or die "Cannot open '$ENV{HOME}/scripts/conf/hmc.list' $!";

my($hmc,$hmctype) = split(":",$_);

if ($hmctype eq "p4") {

chomp(@list = `ssh -q hscroot\@$hmc 'lssyscfg -r sys --all'`);

@managedsystems = ();

my @managedsystems;
for ($i = 1; $i <= scalar @list -1; $i++) {

"scalar @list -1" is the long way of saying "$#list".
$system = substr($list[$i],0,16);
$system =~ s/\s*$//g;

You are using the /g option for a pattern that will only match once (it is
anchored to the end of the string and a string has only one end.) You are
using the * modifier which means that even strings with no whitespace at the
end will be modified. You should use the + modifier instead. Instead of
doing substr() and then substitution you can do both operations with unpack()
(see below.)
push(@managedsystems, $system);
}

for ( @list ) {
push @managedsystems, unpack 'A16', $_;
}

Or doing the declaration and assignment together:

my @managedsystems = map unpack( 'A*', $_ ), @list;
foreach (@managedsystems) {
$system = $_;
$system = "\"".$system."\"";

$system = qq["$_"];
chomp(@list = `ssh -q hscroot\@$hmc 'lssyscfg -m $system -r lpar
--all'`);

for ($i = 2; $i <= scalar @list -1; $i++) {

See above.
$lpar = substr($list[$i],0,20);
$lpar =~ s/\s*$//g;

See above.
print $hmc .":". $system .":". $lpar . "\n";
}

for ( @list ) {
$lpar = unpack 'A20', $_;
print "$hmc:$system:$lpar\n";
}
}
} elsif ($hmctype eq "p5") {
@list = `ssh -q hscroot\@$hmc 'lssyscfg -r sys'`;

@managedsystems = ();

foreach (@list) {
@ln = split(",", $_);
push(@managedsystems, substr($ln[0],5,length($ln[0])));

"substr($ln[0],5,length($ln[0]))" is a long way of saying "substr($ln[0],5))".

push @managedsystems, substr( ( split /,/ )[0], 5 );
}

foreach (@managedsystems) {
$system = $_;
$system =~ s/\s/\\ /g;
@list2 = `ssh -q hscroot\@$hmc 'lssyscfg -r lpar -m $system -F --
header`;
foreach (@list2) {
@ln2 = split(",", $_);
print $hmc .":". $system .":". $ln2[0] . "\n";
}
}
}
}



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top