Loading ...
Sorry, an error occurred while loading the content.

Monitoring ssh connectivity to a server using perl !

Expand Messages
  • Amit Saxena
    Hi all, What s the best way to monitor ssh connectivity, and not just ssh port availability, to a server using perl assuming following constraints ? I tried
    Message 1 of 4 , Nov 23, 2010
    • 0 Attachment
      Hi all,

      What's the best way to monitor ssh connectivity, and not just ssh port
      availability, to a server using perl assuming following constraints ?

      I tried for Net::SSH but public private key is not allowed.

      I tried for Net::SSH::Perl etc but these are not built in perl distribution
      (active perl on windows or part of perl distribution of linux / solaris).

      Can we do it via "IO::Socket::INET" ?

      Thanks & Regards,
      Amit Saxena


      [Non-text portions of this message have been removed]
    • Amit Saxena
      ... Thanks Shawn for the reply. Actually my requirement, to be specific, is as follows. The script will be executed in periodic fashion from a *nix server and
      Message 2 of 4 , Nov 23, 2010
      • 0 Attachment
        On Tue, Nov 23, 2010 at 10:09 PM, shawn wilson <ag4ve.us@...> wrote:

        > Well, each new ssh connection should spawn a new process so you could look
        > at it from that end. More technically, you could look into netstat or lsof
        > modules.
        > On Nov 23, 2010 11:31 AM, "Amit Saxena" <learn.tech123@...> wrote:
        > > Hi all,
        > >
        > > What's the best way to monitor ssh connectivity, and not just ssh port
        > > availability, to a server using perl assuming following constraints ?
        > >
        > > I tried for Net::SSH but public private key is not allowed.
        > >
        > > I tried for Net::SSH::Perl etc but these are not built in perl
        > distribution
        > > (active perl on windows or part of perl distribution of linux / solaris).
        > >
        > > Can we do it via "IO::Socket::INET" ?
        > >
        > > Thanks & Regards,
        > > Amit Saxena
        >

        Thanks Shawn for the reply.

        Actually my requirement, to be specific, is as follows.

        The script will be executed in periodic fashion from a *nix server and the
        script will initiate a ssh connection to itself using perl. This is to
        confirm that the ssh service is running and there is no issue in getting a
        new and authenticated ssh session when clients will connect to the server
        via ssh externally.

        Please suggest.

        Thanks & Regards,
        Amit Saxena


        [Non-text portions of this message have been removed]
      • Joe Pepersack
        Why not just call the ssh client and run a command on the remote host? I d set up a passwordless key to a restricted account for security, but I m paranoid.
        Message 3 of 4 , Nov 23, 2010
        • 0 Attachment
          Why not just call the ssh client and run a command on the remote host?
          I'd set up a passwordless key to a restricted account for security, but
          I'm paranoid.

          open LOG, '>>', '/path/to/logfile' or die "Can't open log file\n";

          foreach my $target ( qw[ user@host1 user@host2 user@localhost ] ) {
          my $uptime = `/usr/bin/ssh -i /path/to/private_key $target uptime`;
          my $now = localtime;

          if ( defined($uptime) ) {
          print LOG "$now\tSSH is up on $target\n";
          }
          else {
          print LOG "$now\tSSH is down on $target\n";
          }
          }

          On 11/23/2010 11:43 AM, Amit Saxena wrote:
          >
          > On Tue, Nov 23, 2010 at 10:09 PM, shawn wilson <ag4ve.us@...
          > <mailto:ag4ve.us%40gmail.com>> wrote:
          >
          > > Well, each new ssh connection should spawn a new process so you
          > could look
          > > at it from that end. More technically, you could look into netstat
          > or lsof
          > > modules.
          > > On Nov 23, 2010 11:31 AM, "Amit Saxena" <learn.tech123@...
          > <mailto:learn.tech123%40gmail.com>> wrote:
          > > > Hi all,
          > > >
          > > > What's the best way to monitor ssh connectivity, and not just ssh port
          > > > availability, to a server using perl assuming following constraints ?
          > > >
          > > > I tried for Net::SSH but public private key is not allowed.
          > > >
          > > > I tried for Net::SSH::Perl etc but these are not built in perl
          > > distribution
          > > > (active perl on windows or part of perl distribution of linux /
          > solaris).
          > > >
          > > > Can we do it via "IO::Socket::INET" ?
          > > >
          > > > Thanks & Regards,
          > > > Amit Saxena
          > >
          >
          > Thanks Shawn for the reply.
          >
          > Actually my requirement, to be specific, is as follows.
          >
          > The script will be executed in periodic fashion from a *nix server and the
          > script will initiate a ssh connection to itself using perl. This is to
          > confirm that the ssh service is running and there is no issue in getting a
          > new and authenticated ssh session when clients will connect to the server
          > via ssh externally.
          >
          > Please suggest.
          >
          > Thanks & Regards,
          > Amit Saxena
          >
          > [Non-text portions of this message have been removed]
          >
          >



          [Non-text portions of this message have been removed]
        • Amit Saxena
          ... Hi Joe, I feel, I have to settle for this option in the end. However is there a way to NOT to use public-private key with ssh and have embedded password in
          Message 4 of 4 , Nov 23, 2010
          • 0 Attachment
            On Wed, Nov 24, 2010 at 1:19 AM, Joe Pepersack <joe@...> wrote:

            >
            >
            > Why not just call the ssh client and run a command on the remote host?
            > I'd set up a passwordless key to a restricted account for security, but
            > I'm paranoid.
            >
            > open LOG, '>>', '/path/to/logfile' or die "Can't open log file\n";
            >
            > foreach my $target ( qw[ user@host1 user@host2 user@localhost ] ) {
            > my $uptime = `/usr/bin/ssh -i /path/to/private_key $target uptime`;
            > my $now = localtime;
            >
            > if ( defined($uptime) ) {
            > print LOG "$now\tSSH is up on $target\n";
            > }
            > else {
            > print LOG "$now\tSSH is down on $target\n";
            >
            > }
            > }
            >
            > On 11/23/2010 11:43 AM, Amit Saxena wrote:
            > >
            > > On Tue, Nov 23, 2010 at 10:09 PM, shawn wilson <ag4ve.us@...<ag4ve.us%40gmail.com>
            > > <mailto:ag4ve.us%40gmail.com <ag4ve.us%2540gmail.com>>> wrote:
            > >
            > > > Well, each new ssh connection should spawn a new process so you
            > > could look
            > > > at it from that end. More technically, you could look into netstat
            > > or lsof
            > > > modules.
            > > > On Nov 23, 2010 11:31 AM, "Amit Saxena" <learn.tech123@...<learn.tech123%40gmail.com>
            > > <mailto:learn.tech123%40gmail.com <learn.tech123%2540gmail.com>>> wrote:
            > > > > Hi all,
            > > > >
            > > > > What's the best way to monitor ssh connectivity, and not just ssh
            > port
            > > > > availability, to a server using perl assuming following constraints ?
            > > > >
            > > > > I tried for Net::SSH but public private key is not allowed.
            > > > >
            > > > > I tried for Net::SSH::Perl etc but these are not built in perl
            > > > distribution
            > > > > (active perl on windows or part of perl distribution of linux /
            > > solaris).
            > > > >
            > > > > Can we do it via "IO::Socket::INET" ?
            > > > >
            > > > > Thanks & Regards,
            > > > > Amit Saxena
            > > >
            > >
            > > Thanks Shawn for the reply.
            > >
            > > Actually my requirement, to be specific, is as follows.
            > >
            > > The script will be executed in periodic fashion from a *nix server and
            > the
            > > script will initiate a ssh connection to itself using perl. This is to
            > > confirm that the ssh service is running and there is no issue in getting
            > a
            > > new and authenticated ssh session when clients will connect to the server
            > > via ssh externally.
            > >
            > > Please suggest.
            > >
            > > Thanks & Regards,
            > > Amit Saxena
            > >
            > > [Non-text portions of this message have been removed]
            > >
            > >
            >
            > [Non-text portions of this message have been removed]
            >
            >
            >

            Hi Joe,

            I feel, I have to settle for this option in the end. However is there a way
            to NOT to use public-private key with ssh and have embedded password in the
            ssh command itself to have non interactive output ?

            Thanks & Regards,
            Amit Saxena


            [Non-text portions of this message have been removed]
          Your message has been successfully submitted and would be delivered to recipients shortly.