title: Perl cgi : running commands on a remote machine
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p><code>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/');</code></p>
  
  <p>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.</p>
  
  <p><code>Host key verification failed</code>.</p>
  
  <p>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? </p>
  
  <p>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.</p>
  
  <p>I can understand that this might be a bit confusing question, please let me know in case any more explianation needed?</p>
  
  <p>The script developed by me is as below:</p>
  
  <pre><code>#!/usr/bin/perl
  use strict;
  use warnings;
  use diagnostics;
  
      printf "Content-type: text/html\n\n";
  
      print &lt;&lt;HTML;
       &lt;HTML&gt;
       &lt;HEAD&gt;
           &lt;TITLE&gt;DataPower_Status&lt;/TITLE&gt;
      &lt;/HEAD&gt;
        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(&lt;FILE&gt;) {
       if ($_ =~ m/^Service/)
         {
             printf "&lt;TR&gt;&lt;TD&gt;&lt;H4&gt;$_&lt;/H4&gt;&lt;/TD&gt;&lt;/TR&gt;\n";
  
         }
         else {
  
             printf "&lt;TR&gt;&lt;TD&gt;&lt;p&gt;$_&lt;/p&gt;&lt;/TD&gt;&lt;/TR&gt;\n";
         }
        }
      close FILE;
  
         print &lt;&lt;HTML;
            &lt;/body&gt;
            &lt;/html&gt;
             HTML
  </code></pre>