Script does not want to run in background ?!?

Script does not want to run in background ?!?

am 23.08.2007 22:28:24 von 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
benoit.lefebvre@gmail.com

Re: Script does not want to run in background ?!?

am 23.08.2007 23:10:21 von Bill H

On Aug 23, 4:28 pm, Benoit Lefebvre wrote:
> 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)
> ------------------------------------------------------------ -------------=
--=AD--------------------------------
> #!/usr/bin/perl
>
> chomp(@hmclist =3D `cat ~/scripts/conf/hmc.list`);
>
> foreach (@hmclist) {
> my($hmc,$hmctype) =3D split(":",$_);
>
> if ($hmctype eq "p4") {
>
> chomp(@list =3D `ssh -q hscroot\@$hmc 'lssyscfg -r sys --all'`);
>
> @managedsystems =3D ();
>
> for ($i =3D 1; $i <=3D scalar @list -1; $i++) {
> $system =3D substr($list[$i],0,16);
> $system =3D~ s/\s*$//g;
> push(@managedsystems, $system);
> }
>
> foreach (@managedsystems) {
> $system =3D $_;
> $system =3D "\"".$system."\"";
>
> chomp(@list =3D `ssh -q hscroot\@$hmc 'lssyscfg -m $system -r lpar
> --all'`);
>
> for ($i =3D 2; $i <=3D scalar @list -1; $i++) {
> $lpar =3D substr($list[$i],0,20);
> $lpar =3D~ s/\s*$//g;
> print $hmc .":". $system .":". $lpar . "\n";
> }
> }
> } elsif ($hmctype eq "p5") {
> @list =3D `ssh -q hscroot\@$hmc 'lssyscfg -r sys'`;
>
> @managedsystems =3D ();
>
> foreach (@list) {
> @ln =3D split(",", $_);
> push(@managedsystems, substr($ln[0],5,length($ln[0])));
> }
>
> foreach (@managedsystems) {
> $system =3D $_;
> $system =3D~ s/\s/\\ /g;
> @list2 =3D `ssh -q hscroot\@$hmc 'lssyscfg -r lpar -m $system -F --
> header`;
> foreach (@list2) {
> @ln2 =3D split(",", $_);
> print $hmc .":". $system .":". $ln2[0] . "\n";
> }
> }
> }}
>
> ------------------------------------------------------------ -------------=
--=AD--------------------------------
>
> ~/scripts/conf/hmc.list contains a list of all HMCs with they type (p4
> or p5) delemited with ":"
>
> Content of hmc.list
> ------------------------------------------------------------ -------------=
--=AD--------------------------------
> name_of_hmc:p4
> name_of_hmc2:p5
> ------------------------------------------------------------ -------------=
--=AD--------------------------------
>
> 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
> benoit.lefeb...@gmail.com

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

Re: Script does not want to run in background ?!?

am 24.08.2007 02:17:37 von Kevin Michael Vail

In article <1187900904.014278.248140@l22g2000prc.googlegroups.com>,
Benoit Lefebvre wrote:

[]

> 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 ?

SIGTTIN means it tried to read from the input TTY, which is not
permitted from a background job (you could bring it to the foreground,
though) or from cron. I have no idea what it's reading, unless 'ssh' is
looking for something.
--
Kevin Michael Vail | a billion stars go spinning through the night,
kevin@vaildc.net   | blazing high above your head.
 . . . . . . . . . | But _in_ you is the presence that
  . . . . . . . .  | will be, when all the stars are dead.
 . . . . . . . . . |     (Rainer Maria Rilke)

Re: Script does not want to run in background ?!?

am 24.08.2007 09:59:06 von Joe Smith

Benoit Lefebvre wrote:

> When I run it from the crontab or in background "&" it fails.
> chomp(@list = `ssh -q hscroot\@$hmc 'lssyscfg -r sys --all'`);

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.

Re: Script does not want to run in background ?!?

am 24.08.2007 15:30:22 von Benoit Lefebvre

On Aug 24, 3:59 am, Joe Smith wrote:
> Benoit Lefebvre wrote:
> > When I run it from the crontab or in background "&" it fails.
> > chomp(@list = `ssh -q hscroot\@$hmc 'lssyscfg -r sys --all'`);
>
> 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
benoit.lefebvre@cn.ca

Re: Script does not want to run in background ?!?

am 25.08.2007 12:04:48 von Dummy

Benoit Lefebvre wrote:
> 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

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' $!";

while ( ) {
chomp;

> 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
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall