#!/usr/perl5/5.8.4/bin/perl ##in ip file ##loading modules use Net::SCP::Expect; ## use warnings; use strict; ##setting gloabal variables my $server=0; my $line=0; my $linepass=0; my $IPFILE=0; ##set default password and user my $user=0; my $password=0; $user="root"; open PASS , "+>>", "passwd.txt" or die $!; foreach $linepass () { chomp($linepass); $password=$linepass; chomp($password); ##open responed ip txt $IPFILE="ip.txt"; open IPFILE , "+>>", "$IPFILE" or die $!; foreach $line () { chomp($line); ##set server to connect to $server=$line; chomp($server); print "\n"; print "Starting SCP command ...\n"; my $scpe = Net::SCP::Expect->new(user=>'root',password=>$password,auto_y es=>1,recursive=>'1'); print "$password $server \n"; #$scpe->login('root',$password); ##sending copy command print "Copying/replacing /etc/resolv.conf ...\n"; $scpe->scp('./resolv.conf',"$server:/etc/resolv.conf"); print "Finished copying resolv.conf to destination\n"; ##replacement finished print "\n"; print "Finished replacing resolv.conf"; close(IPFILE); ##start removing ip from list where resolv.conf was replaced my $cmd="0"; my $grepcmd="\"$server\" ./$IPFILE > ./ip_temp.txt"; $cmd="grep -v $grepcmd"; system("$cmd"); print "\n"; $cmd="rm ./$IPFILE"; system("$cmd"); $cmd="mv ./ip_temp.txt ./$IPFILE"; system("$cmd"); #reopen file for connection loop open IPFILE , "+>>", "$IPFILE" or die $!; ##printing success install to file print "\n"; open RESP, "+>>", "agent_suci.txt" or die $!; print RESP $server; print "$server finished resolv.conf replace"; print RESP "\n"; close(RESP); } } my $cmd="0"; #rename left over ips from iplist to failed_log.txt for future reference $cmd="mv ./$IPFILE ./failed_log.txt"; system("$cmd"); print "resolv.conf script ended failed replacements can be found in failed_log.t xt\n"; exit 0;