#!/usr/bin/perl use Expect; $user = "root"; $pass = "redhat"; $hostname = "localhost"; $comm = "pwd"; $Expect::Log_Stdout = 1; $match = '# '; $session=Expect->spawn("ssh $user\@$hostname") or die "Error calling external program: $!\n"; $session->log_file( 'output.txt' ); unless($session->expect(1,"password: ")) {}; $session->send("$pass\n"); unless ($session->expect(1,'-re', $match)){print "\nNOT FOUND...\n"}; $session->send("$comm\r"); $session->log_file( 'output.txt' );