user2607367
user2607367

Reputation: 225

Using SSH or SCP within perl

I am using ssh within a perl script. I am getting belowe error during the script execution. stderr: Warning: Use of "-b-dor-2-rm" without parentheses is ambiguous at

This is the error thrown by webserver as I am using perl-cgi.

Below is my script:

#!/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

ssh root@sun-b-x-x-x <<'ENDSSH'
cd /tmp/dp/status
./getstatus
ENDSSH

scp -rp root@sun-x-x-x:/tmp/dp/status/DPlive_Status /opt/webserver7/https-sun-b-x-x-x-x/cgi-bin2/datapower/
chmod 777 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

Please let me know where am I committing a mistake? I think the way I am using SSH or SCP is not correct.

Upvotes: 0

Views: 1202

Answers (1)

Barmar
Barmar

Reputation: 782107

To execute a shell command from Perl, you use system():

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

Upvotes: 1

Related Questions