vxp has asked for the wisdom of the Perl Monks concerning the following question:
Hi.
As indicated by 192323, I am trying to write an auto-admin of sorts. This is a VERY rough draft of it, to which I am seeking suggestions, comments, more feature requests, etc.
what i need ideas on is.. right now it can only handle either a 1 IP (which makes it pretty useless) or a class C of IPs. (or any CIDR thats less than class C)
for ($i = 0; $i <= 254; $i++) this line is the problem. a bunch of nested if's (if you arent understanding my idea of how nested if's would fix this.. you shouldn't be reading this anyway) would fix this. but i dont want them, its too ugly.
so..
help. suggest. make feature requests. flames to /dev/null please.
#!/usr/bin/perl use NetAddr::IP; use Net::SSH::Perl; $configfile = "admin.conf"; open(CONFIG, $configfile) or die "Couldn't open config file: $!\n"; while (<CONFIG>) { chomp; s/#.*//; s/^\s+//; next unless length; ($var, $value) = split(/\s*=\s*/, $_, 2); $User_Preferences{$var} = $value; } chop($User_Preferences{IP}); $ip = new NetAddr::IP "$User_Preferences{IP}"; @server_list = $ip->hostenum; for ($i = 0; $i <= 254; $i++) { if ($server_list[$i] =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/) { $period = "."; $server_list[$i] = $1 . $period . $2 . $period . $3 . $period . $4 +; print "$server_list[$i]\n"; } } sub test { foreach $server (@server_list) { $testcmd = "touch /tmp/success.$server"; $ssh = Net::SSH::Perl->new($server); $ssh->login($User_Preferences{USER}, $User_Preferences{PASSWORD}); ($stdout, $stderr, $exit) = $ssh->cmd($testcmd); } } sub restartapache { foreach $server (@server_list) { $apacherestartcmd = "$User_Preferences{APACHEPATH} restart"; $ssh = Net::SSH::Perl->new($server); $ssh->login($User_Preferences{USER}, $User_Preferences{PASSWORD}); ($stdout, $stderr, $exit) = $ssh->cmd($apacherestartcmd); } } if ($User_Preferences{TEST} == 1) { test(); } if ($User_Preferences(RESTARTAPACHE} == 1 { restartapache(); }
Edited: ~Tue Aug 27 23:10:27 2002 (GMT) by footpad: Converted plaintext URL to hyperlink (per Consideration) and added HTML formatting, for readability.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Auto-admin (finally, the code is here! rough draft)
by sauoq (Abbot) on Aug 27, 2002 at 21:53 UTC | |
|
Re: Auto-admin (finally, the code is here! rough draft)
by Zaxo (Archbishop) on Aug 27, 2002 at 20:46 UTC | |
|
Re: Auto-admin (finally, the code is here! rough draft)
by vxp (Pilgrim) on Aug 27, 2002 at 20:10 UTC |