#!/usr/bin/perl use Expect; use strict; use warnings; $Expect::Debug = 1; my $pass= '****'; my $timeout = 1; # chomp (my @devices = `cat sample.txt`); print "@devices\n"; # ## These is to bypass the prompt of each node for new ssh connection. foreach my $device (@devices) { # create an Expect object by spawning another process #push @params, $device; print $device; my $exp = Expect->spawn("ssh-copy-id $device"); if ($exp->expect($timeout, 'password')){ $exp->send("$pass\r"); } }