-
- if ($self->{shellstyle} ne 'sh' and $self->{shellstyle} ne 'csh') {
- croak 'ERROR: Unknown shell style specified. Must be one of "sh" or "csh"', 1;
- } # if
-
- bless ($self, $class);
-
- # now login...
- $self->{handle} = $self->login;
-
- # Set timeout to $default_exec_timeout
- $self->{timeout} = $default_exec_timeout;
-
- return $self->{handle} ? $self : undef;
-} # new
-
-sub execute ($$) {
- my ($self, $cmd, $timeout) = @_;
-
-=pod
-
-=head3 exec ($cmd, $timeout)
-
-This method executes a command on the remote host returning an array
-of lines that the command produced, if any. Status of the command is
-stored in the object and accessible via the status method.
-
-Parameters:
-
-=for html <blockquote>
-
-=over
-
-=item $cmd:
-
-Command to execute remotely
-
-=item $timeout
-
-Set timeout for this execution. If timeout is 0 then wait forever. If
-you wish to interrupt this then set up a signal handler.
-
-=back
-
-=for html </blockquote>
-
-Returns:
-
-=for html <blockquote>
-
-=over
-
-=item @lines
-
-An array of lines from STDOUT of the command. If STDERR is also wanted
-then add STDERR redirection to $cmd. Exit status is not returned by
-retained in the object. Use status method to retrieve it.
-
-=back
-
-=for html </blockquote>
-
-=cut
-
- # If timeout is specified for this exec then use it - otherwise
- # use the object's defined timeout.
- $timeout = $timeout ? $timeout : $self->{timeout};
-
- # If timeout is set to 0 then the user wants an indefinite
- # timeout. But Expect wants it to be undefined. So undef it if
- # it's 0. Note this means we do not support Expect's "check it
- # only one time" option.
- undef $timeout if $timeout == 0;
-
- # If timeout is < 0 then the user wants to run the command in the
- # background and return. We still need to wait as we still may
- # timeout so change $timeout to the $default_exec_timeout in this
- # case and add a "&" to the command if it's not already there.
- # because the user has added a & to the command to run it in the
- if ($timeout && $timeout < 0) {
- $timeout = $default_exec_timeout;
- $cmd .= "&" if $cmd !~ /&$/;
- } # if
-
- # Set status to -2 indicating nothing happened! We should never
- # return -2 (unless a command manages to set $? to -2!)
- $self->{status} = -2;
-
- # Empty lines of any previous command output
- @lines = ();
-
- # Hopefully we will not see the following in the output string
- my $errno_str = "ReXeCerRoNO=";
- my $start_str = "StaRT";
-
- my $compound_cmd;
-
- # If cmd ends in a & then it makes no sense to compose a compound
- # command. The original command will be in the background and thus
- # we should not attempt to get a status - there will be none.
- if ($cmd !~ /&$/) {
- $compound_cmd = "echo $start_str; $cmd; echo $errno_str";
- $compound_cmd .= $self->{shellstyle} eq "sh" ? "\$?" : "\$status";
- } else {
- $compound_cmd = $cmd;
- } # if
-
- $self->{handle}->send ("$compound_cmd\n");
-
- $self->{handle}->expect (
- $timeout,
-
- [ timeout =>
- sub {
- $self->{status} = -1;
- }
- ],
-
- [ qr "\n$start_str",
- sub {
- exp_continue;
- }
- ],
-
- [ qr "\n$errno_str",
- sub {
- my ($exp) = @_;
-
- my $before = $exp->before;
- my $after = $exp->after;
-
- if ($after =~ /(\d+)/) {
- $self->{status} = $1;
- } # if
-
- my @output = split /\n/, $before;
-
- chomp @output;
- chop @output if $output[0] =~ /\r$/;
-
- foreach (@output) {
- next if /^$/;
- last if /$errno_str=/;
-
- push @lines, $_;
- } # foreach
-
- exp_continue;
- }
- ],
-
- [ $self->{prompt},
- sub {
- print 'Hit prompt!' if $debug;
- }
- ],
- );
-
- $self->{lines} = \@lines;
-
- return @lines;
-} # exec
-
-sub abortCmd (;$) {
- my ($self, $timeout) = @_;
-
-=pod
-
-=head3 abortCmd
-
-Aborts the current command by sending a Control-C (assumed to be the
-interrupt character).
-
-Parameters:
-
-=for html <blockquote>
-
-=over
-
-=item None
-
-=back
-
-=for html </blockquote>
-
-Returns:
-
-=for html <blockquote>
-
-=over
-
-=item $status
-
-1 if abort was successful (we got a command prompt back) or 0 if it
-was not.
-
-=back
-
-=for html </blockquote>
-
-=cut
-
- # If timeout is specified for this exec then use it - otherwise
- # use the object's defined timeout.
- $timeout = $timeout ? $timeout : $self->{timeout};
-
- # If timeout is set to 0 then the user wants an indefinite
- # timeout. But Expect wants it to be undefined. So undef it if
- # it's 0. Note this means we do not support Expect's "check it
- # only one time" option.
- undef $timeout if $timeout == 0;
-
- # Set status to -2 indicating nothing happened! We should never
- # return -2 (unless a command manages to set $? to -2!)
- $self->{status} = -2;
-
- $self->{handle}->send ("\cC");
-
- $self->{handle}->expect (
- $timeout,
-
- [ timeout =>
- sub {
- $self->{status} = -1;
- }
- ],
-
- [ $self->{prompt},
- sub {
- print "Hit prompt!" if $debug;
- }
- ],
- );
-
- return $self->{status};
-} # abortCmd
-
-sub status {
- my ($self) = @_;
-
-=pod
-
-=head3 status
-
-Returns the status of the last command executed remotely.
-
-Parameters:
-
-=for html <blockquote>
-
-=over
-
-=item None
-
-=back
-
-=for html </blockquote>
-
-Returns:
-
-=for html <blockquote>
-
-=over
-
-=item $status
-
-Last status from exec.
-
-=back
-
-=for html </blockquote>
-
-=cut
-
- return $self->{status};
-} # status
-
-sub shellstyle {
- my ($self) = @_;
-
-=pod
-
-=head3 shellstyle
-
-Returns the shellstyle
-
-Parameters:
-
-=for html <blockquote>
-
-=over
-
-=item None
-
-=back
-
-=for html </blockquote>
-
-Returns:
-
-=for html <blockquote>
-
-=over
-
-=item "sh"|"csh"
-
-sh: Bourne or csh: for csh style shells
-
-=back
-
-=for html </blockquote>
-
-=cut
-
- return $self->{shellstyle};
-} # shellstyle
-
-sub lines () {
- my ($self) = @_;
-
-=pod
-
-=head3 lines
-
-Returns the lines array from the last command called by exec.
-
-Parameters:
-
-=for html <blockquote>
-
-=over
-
-=item None
-
-=back
-
-=for html </blockquote>
-
-Returns:
-
-=for html <blockquote>
-
-=over
-
-=item @lines
-
-An array of lines from the last call to exec.
-
-=back
-
-=for html </blockquote>
-
-=cut
-
- return @{$self->{lines}};
-} # lines
-
-sub print_lines () {
- my ($self) = @_;
-
-=pod
-
-=head3 print_lines
-
-Essentially prints the lines array to stdout
-
-Parameters:
-
-=for html <blockquote>
-
-=over
-
-=item None
-
-=back
-
-=for html </blockquote>
-
-Returns:
-
-=for html <blockquote>
-
-=over
-
-=item Nothing
-
-=back
-
-=for html </blockquote>
-
-=cut
-
- print "$_\n" foreach ($self->lines);
-
- return;
-} # print_lines
-
-sub getHost () {
- my ($self) = @_;
-
-=pod
-
-=head3 host
-
-Returns the host from the object.
-
-Parameters:
-
-=for html <blockquote>
-
-=over
-
-=item None
-
-=back
-
-=for html </blockquote>
-
-Returns:
-
-=for html <blockquote>
-
-=over
-
-=item $hostname
-
-=back
-
-=for html </blockquote>
-
-=cut
-
- return $self->{host};
-} # getHost
-
-sub DESTROY {
- my ($self) = @_;
-
- $self->{handle}->hard_close
- if $self->{handle};
-
- return;
-} # destroy
-
-sub getTimeout {
- my ($self) = @_;
-
-=head3 getTimeout
-
-Returns the timeout from the object.
-
-Parameters:
-
-=for html <blockquote>
-
-=over
-
-=item None
-
-=back
-
-=for html </blockquote>
-
-Returns:
-
-=for html <blockquote>
-
-=over
-
-=item $timeout
-
-=back
-
-=for html </blockquote>
-
-=cut
-
- return $self->{timeout} ? $self->{timeout} : $default_login_timeout;
-} # getTimeout
-
-sub setTimeout ($) {
- my ($self, $timeout) = @_;
-
-=pod
-
-=head3 setTimeout ($timeout)
-
-Sets the timeout value for subsequent execution.
-
-Parameters:
-
-=for html <blockquote>
-
-=over
-
-=item $timeout
-
-New timeout value to set
-
-=back
-
-=for html </blockquote>
-
-Returns:
-
-=for html <blockquote>
-
-=over
-
-=item $timeout
-
-Old timeout value
-
-=back
-
-=for html </blockquote>
-
-=cut
-
- my $oldTimeout = $self->getTimeout;
- $self->{timeout} = $timeout;
-
- return $oldTimeout;
-} # setTimeout
-
-1;
-
-=head1 DIAGNOSTICS
-
-=head2 Errors
-
-If verbose is turned on then connections or failure to connect will be
-echoed to stdout.
-
-=head3 Error text
-
- <host> is not responding to <protocol>
- Connected to <host> using <protocol> protocol
- Unable to connect to <host> using <protocol> protocol
-
-=head2 Warnings
-
-Specifying cleartext passwords is not recommended for obvious security concerns.
-
-=head1 CONFIGURATION AND ENVIRONMENT
-
-Configuration files and environment variables.
-
-=over
-
-=item None
-
-=back
-
-=head1 DEPENDENCIES
-
-=head2 Perl Modules
-
-=for html <a href="http://search.cpan.org/~rgiersig/Expect-1.21/Expect.pod">Expect</a><b
-
-=head3 ClearSCM Perl Modules
-
-=for html <p><a href="/php/cvs_man.php?file=lib/Display.pm">Display</a></p>
-
-=head1 INCOMPATABILITIES
-
-None yet...
-
-=head1 BUGS AND LIMITATIONS
-
-There are no known bugs in this module.
-
-Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
-
-=head1 LICENSE AND COPYRIGHT
-
-This Perl Module is freely available; you can redistribute it and/or
-modify it under the terms of the GNU General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
-
-This Perl Module is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License (L<http://www.gnu.org/copyleft/gpl.html>) for more
-details.
-
-You should have received a copy of the GNU General Public License
-along with this Perl Module; if not, write to the Free Software Foundation,
-Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-reserved.
-
-=cut
\ No newline at end of file
+
+ if ($self->{shellstyle} ne 'sh' and $self->{shellstyle} ne 'csh') {
+ croak 'ERROR: Unknown shell style specified. Must be one of "sh" or "csh"',
+ } # if
+
+ bless ($self, $class);
+
+ # now login...
+ $self->{handle} = $self->login;
+
+ # Set timeout to $default_exec_timeout
+ $self->{timeout} = $default_exec_timeout;
+
+ return $self->{handle} ? $self : undef;
+} # new
+
+sub execute ($$) {
+ my ($self, $cmd, $timeout) = @_;
+
+=pod
+
+=head3 exec ($cmd, $timeout)
+
+This method executes a command on the remote host returning an array
+of lines that the command produced, if any. Status of the command is
+stored in the object and accessible via the status method.
+
+Parameters:
+
+=for html <blockquote>
+
+=over
+
+=item $cmd:
+
+Command to execute remotely
+
+=item $timeout
+
+Set timeout for this execution. If timeout is 0 then wait forever. If
+you wish to interrupt this then set up a signal handler.
+
+=back
+
+=for html </blockquote>
+
+Returns:
+
+=for html <blockquote>
+
+=over
+
+=item @lines
+
+An array of lines from STDOUT of the command. If STDERR is also wanted
+then add STDERR redirection to $cmd. Exit status is not returned by
+retained in the object. Use status method to retrieve it.
+
+=back
+
+=for html </blockquote>
+
+=cut
+
+ # If timeout is specified for this exec then use it - otherwise
+ # use the object's defined timeout.
+ $timeout = $timeout ? $timeout : $self->{timeout};
+
+ # If timeout is set to 0 then the user wants an indefinite
+ # timeout. But Expect wants it to be undefined. So undef it if
+ # it's 0. Note this means we do not support Expect's "check it
+ # only one time" option.
+ undef $timeout if $timeout == 0;
+
+ # If timeout is < 0 then the user wants to run the command in the
+ # background and return. We still need to wait as we still may
+ # timeout so change $timeout to the $default_exec_timeout in this
+ # case and add a "&" to the command if it's not already there.
+ # because the user has added a & to the command to run it in the
+ if ($timeout && $timeout < 0) {
+ $timeout = $default_exec_timeout;
+ $cmd .= "&" if $cmd !~ /&$/;
+ } # if
+
+ # Set status to -2 indicating nothing happened! We should never
+ # return -2 (unless a command manages to set $? to -2!)
+ $self->{status} = -2;
+
+ # Empty lines of any previous command output
+ @lines = ();
+
+ # Hopefully we will not see the following in the output string
+ my $errno_str = "ReXeCerRoNO=";
+ my $start_str = "StaRT";
+
+ my $compound_cmd;
+
+ # If cmd ends in a & then it makes no sense to compose a compound
+ # command. The original command will be in the background and thus
+ # we should not attempt to get a status - there will be none.
+ if ($cmd !~ /&$/) {
+ $compound_cmd = "echo $start_str; $cmd; echo $errno_str";
+ $compound_cmd .= $self->{shellstyle} eq "sh" ? "\$?" : "\$status";
+ } else {
+ $compound_cmd = $cmd;
+ } # if
+
+ $self->{handle}->send ("$compound_cmd\n");
+
+ $self->{handle}->expect (
+ $timeout,
+
+ [ timeout =>
+ sub {
+ $self->{status} = -1;
+ }
+ ],
+
+ [ qr "\n$start_str",
+ sub {
+ exp_continue;
+ }
+ ],
+
+ [ qr "\n$errno_str",
+ sub {
+ my ($exp) = @_;
+
+ my $before = $exp->before;
+ my $after = $exp->after;
+
+ if ($after =~ /(\d+)/) {
+ $self->{status} = $1;
+ } # if
+
+ my @output = split /\n/, $before;
+
+ chomp @output;
+ chop @output if $output[0] =~ /\r$/;
+
+ foreach (@output) {
+ next if /^$/;
+ last if /$errno_str=/;
+
+ push @lines, $_;
+ } # foreach
+
+ exp_continue;
+ }
+ ],
+
+ [ $self->{prompt},
+ sub {
+ print 'Hit prompt!' if $debug;
+ }
+ ],
+ );
+
+ $self->{lines} = \@lines;
+
+ return @lines;
+} # exec
+
+sub abortCmd (;$) {
+ my ($self, $timeout) = @_;
+
+=pod
+
+=head3 abortCmd
+
+Aborts the current command by sending a Control-C (assumed to be the
+interrupt character).
+
+Parameters:
+
+=for html <blockquote>
+
+=over
+
+=item None
+
+=back
+
+=for html </blockquote>
+
+Returns:
+
+=for html <blockquote>
+
+=over
+
+=item $status
+
+1 if abort was successful (we got a command prompt back) or 0 if it
+was not.
+
+=back
+
+=for html </blockquote>
+
+=cut
+
+ # If timeout is specified for this exec then use it - otherwise
+ # use the object's defined timeout.
+ $timeout = $timeout ? $timeout : $self->{timeout};
+
+ # If timeout is set to 0 then the user wants an indefinite
+ # timeout. But Expect wants it to be undefined. So undef it if
+ # it's 0. Note this means we do not support Expect's "check it
+ # only one time" option.
+ undef $timeout if $timeout == 0;
+
+ # Set status to -2 indicating nothing happened! We should never
+ # return -2 (unless a command manages to set $? to -2!)
+ $self->{status} = -2;
+
+ $self->{handle}->send ("\cC");
+
+ $self->{handle}->expect (
+ $timeout,
+
+ [ timeout =>
+ sub {
+ $self->{status} = -1;
+ }
+ ],
+
+ [ $self->{prompt},
+ sub {
+ print "Hit prompt!" if $debug;
+ }
+ ],
+ );
+
+ return $self->{status};
+} # abortCmd
+
+sub status {
+ my ($self) = @_;
+
+=pod
+
+=head3 status
+
+Returns the status of the last command executed remotely.
+
+Parameters:
+
+=for html <blockquote>
+
+=over
+
+=item None
+
+=back
+
+=for html </blockquote>
+
+Returns:
+
+=for html <blockquote>
+
+=over
+
+=item $status
+
+Last status from exec.
+
+=back
+
+=for html </blockquote>
+
+=cut
+
+ return $self->{status};
+} # status
+
+sub shellstyle {
+ my ($self) = @_;
+
+=pod
+
+=head3 shellstyle
+
+Returns the shellstyle
+
+Parameters:
+
+=for html <blockquote>
+
+=over
+
+=item None
+
+=back
+
+=for html </blockquote>
+
+Returns:
+
+=for html <blockquote>
+
+=over
+
+=item "sh"|"csh"
+
+sh: Bourne or csh: for csh style shells
+
+=back
+
+=for html </blockquote>
+
+=cut
+
+ return $self->{shellstyle};
+} # shellstyle
+
+sub lines () {
+ my ($self) = @_;
+
+=pod
+
+=head3 lines
+
+Returns the lines array from the last command called by exec.
+
+Parameters:
+
+=for html <blockquote>
+
+=over
+
+=item None
+
+=back
+
+=for html </blockquote>
+
+Returns:
+
+=for html <blockquote>
+
+=over
+
+=item @lines
+
+An array of lines from the last call to exec.
+
+=back
+
+=for html </blockquote>
+
+=cut
+
+ return @{$self->{lines}};
+} # lines
+
+sub print_lines () {
+ my ($self) = @_;
+
+=pod
+
+=head3 print_lines
+
+Essentially prints the lines array to stdout
+
+Parameters:
+
+=for html <blockquote>
+
+=over
+
+=item None
+
+=back
+
+=for html </blockquote>
+
+Returns:
+
+=for html <blockquote>
+
+=over
+
+=item Nothing
+
+=back
+
+=for html </blockquote>
+
+=cut
+
+ print "$_\n" foreach ($self->lines);
+
+ return;
+} # print_lines
+
+sub getHost () {
+ my ($self) = @_;
+
+=pod
+
+=head3 host
+
+Returns the host from the object.
+
+Parameters:
+
+=for html <blockquote>
+
+=over
+
+=item None
+
+=back
+
+=for html </blockquote>
+
+Returns:
+
+=for html <blockquote>
+
+=over
+
+=item $hostname
+
+=back
+
+=for html </blockquote>
+
+=cut
+
+ return $self->{host};
+} # getHost
+
+sub DESTROY {
+ my ($self) = @_;
+
+ $self->{handle}->hard_close
+ if $self->{handle};
+
+ return;
+} # destroy
+
+sub getTimeout {
+ my ($self) = @_;
+
+=head3 getTimeout
+
+Returns the timeout from the object.
+
+Parameters:
+
+=for html <blockquote>
+
+=over
+
+=item None
+
+=back
+
+=for html </blockquote>
+
+Returns:
+
+=for html <blockquote>
+
+=over
+
+=item $timeout
+
+=back
+
+=for html </blockquote>
+
+=cut
+
+ return $self->{timeout} ? $self->{timeout} : $default_login_timeout;
+} # getTimeout
+
+sub setTimeout ($) {
+ my ($self, $timeout) = @_;
+
+=pod
+
+=head3 setTimeout ($timeout)
+
+Sets the timeout value for subsequent execution.
+
+Parameters:
+
+=for html <blockquote>
+
+=over
+
+=item $timeout
+
+New timeout value to set
+
+=back
+
+=for html </blockquote>
+
+Returns:
+
+=for html <blockquote>
+
+=over
+
+=item $timeout
+
+Old timeout value
+
+=back
+
+=for html </blockquote>
+
+=cut
+
+ my $oldTimeout = $self->getTimeout;
+ $self->{timeout} = $timeout;
+
+ return $oldTimeout;
+} # setTimeout
+
+1;
+
+=head1 DIAGNOSTICS
+
+=head2 Errors
+
+If verbose is turned on then connections or failure to connect will be
+echoed to stdout.
+
+=head3 Error text
+
+ <host> is not responding to <protocol>
+ Connected to <host> using <protocol> protocol
+ Unable to connect to <host> using <protocol> protocol
+
+=head2 Warnings
+
+Specifying cleartext passwords is not recommended for obvious security concerns.
+
+=head1 CONFIGURATION AND ENVIRONMENT
+
+Configuration files and environment variables.
+
+=over
+
+=item None
+
+=back
+
+=head1 DEPENDENCIES
+
+=head2 Perl Modules
+
+=for html <a href="http://search.cpan.org/~rgiersig/Expect-1.21/Expect.pod">Expect</a>
+
+=head3 ClearSCM Perl Modules
+
+=for html <p><a href="/php/scm_man.php?file=lib/Display.pm">Display</a></p>
+
+=head1 INCOMPATABILITIES
+
+None yet...
+
+=head1 BUGS AND LIMITATIONS
+
+There are no known bugs in this module.
+
+Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
+
+=head1 LICENSE AND COPYRIGHT
+
+This Perl Module is freely available; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+This Perl Module is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License (L<http://www.gnu.org/copyleft/gpl.html>) for more
+details.
+
+You should have received a copy of the GNU General Public License
+along with this Perl Module; if not, write to the Free Software Foundation,
+Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+reserved.
+
+=cut