#!/usr/bin/perl use strict; use warnings; use diagnostics; use Net::SSH::Expect; my $ssh = Net::SSH::Expect->new ( host => "host", user => 'user', password => 'password', raw_pty => 1, timeout => 5 ); eval { my $login_output = $ssh->login(); if ($login_output !~ /Welcome/) { die "Login has failed. Login output was $login_output"; } }; $ssh->exec("stty raw -echo"); my $whoami = $ssh->exec('whoami'); print $whoami, "\n"; my $ls = $ssh->exec('ls -l /'); print $ls, "\n";