for my $site( @fix ) { my $ssh=Expect->spawn( "/usr/bin/ssh $user\@$site" ) or die "could not create ssh Expect object: $!\n"; $ssh->expect( TIMEOUT," password: ") or die "Never got password prompt from $site: $!\n"; print $ssh "password\n"); my @cmds = ( 'set dhcp server option dns1 10.0.0.1', 'set dhcp server option dns2 10.0.0.2', 'save', 'exit', ); for my $cmd( @cmds ) { $ssh->expect( TIMEOUT, "$site>" ) or die "Never got command prompt from $site: $!\ndid not send [$cmd]\n"; print $ssh "$cmd\n"; } sleep 1; $ssh->soft_close(); }