For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > June 2007 > Re: SSH plus tail -f without key exchange possible?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: SSH plus tail -f without key exchange possible?
jrpfinch

2007-06-25, 7:10 pm

I am come across a further problem. Currently my code looks like
this:

[snip]
{
$dieOutput = undef;
local $SIG{ALRM} = sub { die "Timed out" };
alarm 10;
eval("\$conn = Net::SSH::Perl -> new ('$host', protocol => 2);".
"\$conn->login('$user','$password')");
alarm 0;
$dieOutput = $@ if $@;
}

$conn->register_handler("stdout", sub { #do stuff# })

$conn->cmd("tail -f somefile");

# part 2 - when connection dies/terminated do some more stuff

The problem with this is that if the script terminates for some
reason, I am left with an orphan tail -f process on the remote
machine. Also, I would like to be able to put something in the
register_handler to kill the connection if a certain line appears in
somefile.

Any ideas? Or am I going about this in completely the wrong way? I
would like to avoid Net::SSH2 if possible, as this would require a
rewrite and I am unable to compile the libssh2 libraries on Solaris 9.

xhoster@gmail.com

2007-06-25, 7:10 pm

jrpfinch <jrpfinch@gmail.com> wrote:
> I am come across a further problem. Currently my code looks like
> this:
>
> [snip]
> {
> $dieOutput = undef;
> local $SIG{ALRM} = sub { die "Timed out" };
> alarm 10;
> eval("\$conn = Net::SSH::Perl -> new ('$host', protocol => 2);".
> "\$conn->login('$user','$password')");
> alarm 0;
> $dieOutput = $@ if $@;
> }
>
> $conn->register_handler("stdout", sub { #do stuff# })
>
> $conn->cmd("tail -f somefile");
>
> # part 2 - when connection dies/terminated do some more stuff
>
> The problem with this is that if the script terminates for some
> reason, I am left with an orphan tail -f process on the remote
> machine.


I suspect, but do not know for certain, that once the file grows to the
point that the remote tail -f has filled up it's pipe buffer, it will die.
If the file grows slowly, that might take a while.

> Also, I would like to be able to put something in the
> register_handler to kill the connection if a certain line appears in
> somefile.


How about just dying inside the register_handler? It should kill the
client end of the connection, at least.

I'd consider writing a Perl script to be used in the place of tail -f on
the remote machine. You can have the Perl script quite on the remote side
when it sees the qualifying line. It could also handle the time-out.

http://groups.google.com/group/comp...2b07d4640c02b15

>
> Any ideas? Or am I going about this in completely the wrong way? I
> would like to avoid Net::SSH2 if possible, as this would require a
> rewrite and I am unable to compile the libssh2 libraries on Solaris 9.



Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
xhoster@gmail.com

2007-06-25, 7:10 pm

Some moron named xhoster@gmail.com wrote:

> I suspect, but do not know for certain, that once the file grows to the
> point that the remote tail -f has filled up it's pipe buffer, it will


its, not it's.

> I'd consider writing a Perl script to be used in the place of tail -f on
> the remote machine. You can have the Perl script quite


quit, not quite.

Sigh.

I used to think Perl was my first language. Now I'm starting to think it
is my only language.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
anno4000@radom.zrz.tu-berlin.de

2007-06-25, 7:10 pm

<xhoster@gmail.com> wrote in comp.lang.perl.misc:

> I used to think Perl was my first language. Now I'm starting to think it
> is my only language.


Hehe.

Anno
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com