#!/usr/local/bin/perl
#
# Reset 3Com device
#
# Jim Trocki
#
# $Id: 3creset,v 1.7 1999/04/06 15:25:55 trockij Exp $
#
# Copyright (C) 1998 Jim Trocki
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
use A3Com::Sys;
use Getopt::Std;

sub help;

getopts ("h", \%opt);

help() if ($opt{"h"} || @ARGV == 0);

$COMM = A3Com::Sys::get_password ("Write community: ");

die "no community specified\n" if ($COMM =~ /^\s*$/);

foreach $HOST (@ARGV) {
    my ($r, $v) = A3Com::Sys::reset (
	host => $HOST,
	community => $COMM,
    );

    if (!defined $r) {
	print "$HOST not reset: $v\n";
	next;
    }

    print "$HOST reset\n";
}


sub help {
    print <<EOF;
usage: 3creset host [host...]

    SNMP write community is accepted from an interactive prompt if stdin
    is a tty, otherwise from stdin.

EOF
    exit;
}
