#!/usr/bin/perl use strict; use warnings; use Net::SCP::Expect; my $remote_host = "xxx.xxx.xxx.xxx"; my $password = "xxxxxx"; my $username = "xxxxxx"; my $ssh = Net::SSH::Perl->new($remote_host, protocol=>'1', options => [ "UserKnownHostsFile /home/apache/.ssh/known_hosts" ]) or die("could not connect"); print "ssh set\n"; $ssh->login($username, $password); print "login done\n"; my $test_dir = "/foo/bar/"; my $cmd = "if [ -d $test_dir ]; then echo 1; else echo 0; fi"; print "CMD: $cmd\n"; my($stdout, $stderr, $exit) = $ssh->cmd($cmd); print "STDOUT: $stdout STDERR: $stderr EXIT: $exit\n";