Académique Documents
Professionnel Documents
Culture Documents
my @ftree = map
{ to parent's Child
# add
list ( $found );
unless
s/\s+$//; push( @{# $node->{'Parent'}->{'Children'}
trim
ends;
# add to parent's Child list
}, $node )
my $depth = if
s/\s{4}//g;
#
count
number
of
indent
blocks
push( @{ $node->{'Parent'}->{'Children'}
}, $node )
( $node->{'Parent'}
);
my
@ancestry
=
(
$node
);
$depth++;
# Start
at one, though, rather
if ( $node->{'Parent'}
); than 0
by Mark Schoonover
$parent_stack[ $depth
] =( $found->{'Parent'}->{'Depth'}
$node;
while
>= 1 )
mark.schoonover@gmail.com
# create node structure$parent_stack[ $depth ] = $node;
{
my $node =$node;
{
pushuse
@ancestry,
$found->{'Parent'}->{'Name'};
Name
$_,
magine having to change
the{password
on $node;
hundreds
of
Expect;
} grep
! =>
m/^\s*$/
} @lines;
#
strip
out
blank
lines
servers. I could log in toDepth
each one individually
and hope to $found = $found->{'Parent'};
=>}$depth,
grep
{
!
m/^\s*$/
}
@lines;
#
strip
out blank lines
get done before I retire, or I could use Perl with Expect.pm
my $expect = Expect->new;
Parent
=>error,
$parent_stack[
to accomplish this very quickly,
with
less
by automating $depth - 1 ],
return
\@ftree;
it. Anything I can manually
do on the command
line I can
my $login =
Children
=>
[], \@ftree;
return
automate with the Expect module.
"/usr/local/bin/ssh $user\@$host";
};
my $expect = Expect->spawn($login)
Expecting Perl
n Introduction------------------------------------------------------
or die
"Can't login to $host as $user: $!\n"
Where $host and $user are valid host and user names. If this
method call dies, I wont be able to send any commands to the
host. To help in debugging my Expect scripts, I enable logging
by setting $Expect::Exp_Interval to a true value:
n Connecting and Logging In--------------------------------I can connect to my target system in several ways, including
various Perl modules such as Net::SSH, Net::SSH::Expect,
or Net::Telnet, etc. SSH is installed on my systems, so I
use that directly. I construct a command, just like I would
if I were doing this myself. I execute that command with the
spawn method:
www.theperlreview.com