sub connect { my $host = shift; my $SSH = Expect->spawn (@ssh, "$user\@$host"); my ($match_num, $error, $match, $before, $after) = $SSH->expect ($time, '-re', '[Nn]ew [Pp]assword:', '-re', '^[Pp]assword.*:', '-re', $prompt); if ($match_num == 1) { $result = "FAILED: Account Expired"; return; } if ($match_num == 3) { $result = "SUCCESS: you are logged into $host"; return; } if ($match_num != 2) { $before =~ s/\r\n//g; $after =~ s/\r\n//g; $result = "ERROR: $error BEFORE: $before AFTER: $after"; return; } print $SSH "$pass\r"; ($match_num, $error, $match, $before, $after) = $SSH->expect ($time, '-re', '[Pp]assword.*:', '-re', $prompt); if ($match_num == 1) { $result = "FAILED: Incorrect Password"; return; } if ($match_num == 3) { $result = "SUCCESS: you are logged into $host"; return; } return if ($match_num != 2); print $SSH "export PS1='scripts: '\r"; ($match_num, $error, $match, $before, $after) = $SSH->expect ($time, '-re', '\r\nscripts: '); if ($match_num == 1) { $result = "SUCCESS: you are logged into $host"; return; } $before =~ s/\r\n//g; $after =~ s/\r\n//g; $result = "ERROR: $error BEFORE: $before AFTER: $after"; }