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.


In reply to Auto-admin (finally, the code is here! rough draft) by vxp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.