user2607367
user2607367

Reputation: 225

Perl cgi : running commands on a remote machine

I need to see a current status of DataPower services on a browser.For this, I have developed a perl cgi script on a solaris machine.

I have a cgi webserver running on a solaris server from which I don't have a direct connectivity to DataPower appliance.hence through the script I am connecting to a remote Solaris server 'sun-rm' which has a connectivity to DataPower appliance.

Using the below two statements in the script I am trying to run the commands on remote server 'sun-rm' which will get the current stats of daatpower service.

system('ssh root@sun-rm "cd /tmp/dp/status; ./getstatus"'); system('scp -rp root@sun-rm:/tmp/dp/status/DPlive_Status /opt/webserver/https-util/cgi-bin2/datapower/');

but it seems that the webserver is not able to make secure connection with 'sun-rm' server as I can see below error in errors logs.

Host key verification failed.

Now, due to some security reason I cnt add the key of 'sun-rm' server to webserver's trust store. Is there any way using which the commands can be run on a remote machine?

Further, this webserver is installed on solaris machine 'sun-util', from which I can do ssh to 'sun-rm'. But the ssh connection from webserver to 'sun-rm' cant be established due to the reason mentioned above.

I can understand that this might be a bit confusing question, please let me know in case any more explianation needed?

The script developed by me is as below:

#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;

    printf "Content-type: text/html\n\n";

    print <<HTML;
     <HTML>
     <HEAD>
         <TITLE>DataPower_Status</TITLE>
    </HEAD>
      HTML

    system('ssh root@sun-rm "cd /tmp/dp/status; ./getstatus"');
    system('scp -rp root@sun-rm:/tmp/dp/status/DPlive_Status     /opt/webserver7/https-util/cgi-bin2/datapower/');

 chmod(0777, '/opt/webserver7/https-util/cgi-bin2/datapower/DPlive_Status');

 open (FILE, "DPlive_Status") or die "could not open filename";
   while(<FILE>) {
     if ($_ =~ m/^Service/)
       {
           printf "<TR><TD><H4>$_</H4></TD></TR>\n";

       }
       else {

           printf "<TR><TD><p>$_</p></TD></TR>\n";
       }
      }
    close FILE;

       print <<HTML;
          </body>
          </html>
           HTML

Upvotes: 0

Views: 994

Answers (1)

Sobrique
Sobrique

Reputation: 53498

That's an SSH error, which means the cached host key identity isn't valid. This typically occurs if you've got a cluster, with different ssh host keys - your client caches a key for that hostname in .ssh/known_hosts.

First workaround is delete the key from known_hosts and try again. Second workaround is enable an ssh option to disable strict host key checking. StrictHostKeyChecking=no

But first you REALLY want to make sure why the host key isn't valid - this could be very bad news. (More likely it's a server rebuild, cluster migrate or something like that, but it really does pay to check)

Upvotes: 1

Related Questions