Leser: 24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/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 (<PASS>)
{
chomp($linepass);
$password=$linepass;
chomp($password);
##open responed ip txt
$IPFILE="ip.txt";
open IPFILE , "+>>", "$IPFILE" or die $!;
foreach $line (<IPFILE>)
{
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;
IPNEXT: foreach $line (<IPFILE>)
1
2
3
4
5
6
my $scpe;
# Login versuchen
eval { $scpe = Net::SCP::Expect->new(user=>'root',password=>$password,auto_yes=>1,recursive=>'1'); };
if ($@ && $@ =~ /Error: Bad Password/) { # falls Loginfehler
next IPNEXT; # versuche nächstes Login
}