in reply to Re: cpan module to do stuff remotely
in thread cpan module to do stuff remotely

Hi Thomas,

Well I think I said but I'm not sure yet whether they meet my needs. My needs are to run commands, trap errors and log output (as above) and I need to work through a firewall. I haven't tested Net:SSH yet, but it seems to be interactive and I'm not sure how you connect through a gateway if you don't have a dedicated IP address for the machine being maintained and the ports aren't forwarded. As I say I need to do some checking. Maybe it does everything I need.

At the moment, I imagine the remote programme with regularly check a file on a website and execute the instructions in it.

Regards

Steve

Replies are listed 'Best First'.
Re^3: cpan module to do stuff remotely
by thomas895 (Deacon) on Jun 05, 2012 at 23:52 UTC

    Net::SSH, or the OO Net::SSH::Perl is easy to use:

    #!/usr/bin/perl -wT use Net::SSH::Perl; use feature qw( say ); my $ssh = Net::SSH::Perl->new( "1.2.3.4" ); $ssh = Net::SSH::Perl->new( "my.host.name" ); #You can use a hostname $ssh->login( "zaphod", "twoheads2" ); my($stdout, $stderr, $exit) = $ssh->cmd( "cat /dev/universe" ); say "The command said: $stdout"; say "The command error'd: $stderr"; say "The command's exit status was $exit";

    You can always do it yourself if you really must, with IO::Socket, or even Socket if you dare.

    ~Thomas~
    confess( "I offer no guarantees on my code." );

      Hi Thomas,

      Ok, I can see what it's doing. Thanks for the sample code.

      It looks great if I could use it. It's exactly how I would like to operate, but I have no way of getting through the remote firewall, the machine could be in a hotel or a hospital with a wireless router and also no way of port-forwarding my connection to the remote machine.

      So I think it needs to be *pulled* by the remote host. My local machine, also behind a router/firewall, then needs to post a file or files on a convenient server, the remote host will regularly check the server, download and execute the code.

      So it's really only the my($stdout, $stderr, $exit) = $ssh->cmd( "cat /dev/universe" ); bit that I want.

      So I probably need to use Net::FTP to download the file(s) according to some sort of schedule. And then maybe IPC::RunExternal for each line.

      What do you think?

      Thanks for your input.

      Regards

      Steve.

        I have no way of getting through the remote firewall
        That is a network issue that you will have to work out with your network admin, or if that is you, figure out on your router. That, however, is out of this forum's scope.

        What do you think?
        Well, I don't know. If that accomplishes your goal, then that is the way to go. And don't limit yourself to Perl. Sometimes, cron can be a better and more reliable alternative, plus it is built in to your OS. On Windoze, you would use the task scheduler or what have you.
        On an unrelated side note: Windoze is terrible for programming anything useful on.

        ~Thomas~
        confess( "I offer no guarantees on my code." );