From: AJ Lewis Message-ID: <20020611141314.GB18172@roadrunner.sistina.com> References: <20020610172902.U30763@sistina.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="J2SCkAp4GZ/dPZZf" Content-Disposition: inline In-Reply-To: <20020610172902.U30763@sistina.com> Subject: [linux-lvm] Re: do_apc_ms stomith Sender: linux-lvm-admin@sistina.com Errors-To: linux-lvm-admin@sistina.com Reply-To: linux-lvm@sistina.com List-Help: List-Post: List-Subscribe: , List-Unsubscribe: , List-Archive: Date: Tue Jun 11 09:11:01 2002 List-Id: To: Adam Manthei , linux-lvm@sistina.com --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable I think this is probably good enough AFAIAC: !!! ERROR DETECTED in /home/vortex/src/GFS/bin/do_apc_ms -h !!! o Options out of order: -q >=3D -p=20 !!! END OF ERRORS !!! !!! ERROR DETECTED in /home/vortex/src/GFS/bin/do_apc_ms -Z !!! o invalid error message (line 1): Unknown option: Z !!! END OF ERRORS !!! Just the missing flag errors need to be changed other than that. On Mon, Jun 10, 2002 at 05:29:02PM -0500, Adam Manthei wrote: > Let me know how this does against your ruby script. >=20 > It's some what of an improvement... but things are starting to get real > ugly. =20 > =20 > --=20 > Adam Manthei > #!/usr/bin/perl >=20 > #########################################################################= ###### > #########################################################################= ###### > ## > ## Copyright (C) Sistina Software, Inc. 1997-2001 All rights reserved. > ## > #########################################################################= ###### > #########################################################################= ###### >=20 > use Getopt::Std; > use Net::Telnet (); >=20 > # WARNING!! Do not add code bewteen "#BEGIN_VERSION_GENERATION" and=20 > # "#END_VERSION_GENERATION" It is generated by the Makefile >=20 > #BEGIN_VERSION_GENERATION > $GFS_RELEASE_NAME=3D""; > $SISTINA_COPYRIGHT=3D""; > $BUILD_DATE=3D""; > #END_VERSION_GENERATION >=20 > # Get the program name from $0 and strip directory names > $_=3D$0; > s/.*\///; > my $pname =3D $_; >=20 > # Change these if the text returned by your equipment is different. > # Test by running script with options -t -v and checking /tmp/apclog >=20 > my $immediate =3D 'immediate'; # Or 'delayed' - action string prefix on m= enu > my $masterswitch =3D 'masterswitch plus '; # 'Device Manager' option to c= hoose > my $login_prompt =3D '/: /'; > my $cmd_prompt =3D '/> /'; >=20 > my $max_open_tries =3D 1; # How many telnet attempts to make > my $open_wait =3D 5; # Seconds to wait between each telnet atte= mpt > my $telnet_timeout =3D 20; # Seconds to wait for matching telent resp= onse > my $opt_o =3D 'reboot'; # Default fence action >=20 > sub fail > { > ($msg)=3D@_; > print $msg."\n" unless defined $opt_q; > $t->close if defined $t; > exit 1; > } >=20 > sub fail_usage > { > ($msg)=3D@_; > printf stderr $msg."\n" if $msg; > print stderr "Please use '-h' for usage.\n"; > exit 1; > } >=20 >=20 > sub usage=20 > { > print "Usage:\n"; > print "\n"; > print "$pname [options]\n"; > print "\n"; > print "Options:\n"; > print " -a IP address or hostname of MasterSwitch\n"; > print " -h usage\n"; > print " -l Login name\n"; > print " -n Outlet number to change: [:] \n"; > print " -o Action: Reboot (default), Off or On\n"; > print " -q quiet mode\n"; > print " -p Login password\n"; > print " -T Test mode (cancels action)\n"; > print " -V version\n"; > print " -v Log to file /tmp/apclog\n"; >=20 > exit 0; > } >=20 > sub version > { > print "$pname $GFS_RELEASE_NAME $BUILD_DATE\n"; > print "$SISTINA_COPYRIGHT\n" if ( $SISTINA_COPYRIGHT ); >=20 > exit 0; > } >=20 >=20 > if (@ARGV > 0) { > $opt_name =3D $pname; > getopts("a:hl:n:o:p:qTvV") || fail_usage ; >=20 > usage if defined $opt_h; > version if defined $opt_V; >=20 > fail_usage "too many parameters" if (@ARGV > 0); >=20 > fail_usage "failed: $opt_name no IP address" unless defined $opt_a; > fail_usage "failed: $opt_name no plug number" unless defined $opt_n; > fail_usage "failed: $opt_name no login name" unless defined $opt_l; > fail_usage "failed: $opt_name no password" unless defined $opt_p; > fail_usage "failed: $opt_name unrecognised action: $opt_o" > unless $opt_o =3D~ /^(Off|On|Reboot)$/i; >=20 > } else { > get_options_stdin(); >=20 > fail "failed: $opt_name no IP address" unless defined $opt_a; > fail "failed: $opt_name no plug number" unless defined $opt_n; > fail "failed: $opt_name no login name" unless defined $opt_l; > fail "failed: $opt_name no password" unless defined $opt_p; > fail "failed: $opt_name unrecognised action: $opt_o" > unless $opt_o =3D~ /^(Off|On|Reboot)$/i; > } >=20 >=20 > if ( $opt_n =3D~ /(\d+):(\d+)/ ) { > my $switchnum=3D($1); > $opt_n =3D ($2); > $masterswitch =3D $masterswitch . $switchnum; > } else { > $masterswitch =3D $masterswitch . "1"; > } >=20 > my $t =3D new Net::Telnet; > $t->timeout($telnet_timeout); >=20 > $t->input_log('/tmp/apclog') > if $opt_v; >=20 > &login; > &navigate; > &action; >=20 > exit 0; >=20 >=20 > sub login > { > # Opt to return on failure and we'll retry > $t->errmode('return'); =20 >=20 > for (my $i=3D0; $i<$max_open_tries; $i++) > { > $t->open($opt_a); > ($_) =3D $t->waitfor($login_prompt); > =20 > # Expect 'User Name : '=20 > if (! /name/i) { > $t->close; > sleep($open_wait); > next; =20 > } >=20 > $t->print($opt_l); > ($_) =3D $t->waitfor($login_prompt); > =20 > # Expect 'Password : '=20 > if (! /password/i ) { > $t->close; > sleep($open_wait); > next; =20 > } > =20 > # Send password > $t->print($opt_p); =20 > # No point retrying if we get this far e.g. if password is rejected > return; > } > fail "failed: $opt_name - telnet failed: ". $t->errmsg."\n"=20 > } >=20 >=20 >=20 > # Navigate through menus to the appropriate outlet control menu. > # Uses multi-line (mostly) case-insensitive matches to recognise menus > # and works out what option number to select from each menu. >=20 > sub navigate > { > # Abort on failure beyond here > $t->errmode(\&telnet_error); =20 > while(1) > { > # Get the new text from the menu > ($_) =3D $t->waitfor($cmd_prompt); >=20 > # Identify next option=20 > if (=20 > # "Control Console", "1- Device Manager" > /--\s*control console.*(\d+)\s*-\s*device manager/is || >=20 > # "Device Manager", "1- MasterSwitch plus 1" > /--\s*device manager.*(\d+)\s*-\s*$masterswitch/is || >=20 > # "Device Manager", "1- Cluster Node 0 ON" > /--\s*(?:device manager|$masterswitch).*($opt_n)\s*-[^\n]*\s(?-= i:ON|OFF)\*?\s/ism || >=20 > # "MasterSwitch plus 1", "1- Outlet 1:1 Outlet #1 ON" > /--\s*$masterswitch.*(\d+)\s*-\s*Outlet\s+$opt_n\s[^\n]*\s(?-i:= ON|OFF)\*?\s/ism || >=20 > # Outlet Control > /(\d+)\s*-\s*((Control|Outlet)\s?){2}\s*(\d+:)?$opt_n\s/i=20 > ) { > $t->print($1); > next; > } >=20 > # "Outlet Control X:N", "4- Immediate Reboot" > if ( /(\d+)\s*-\s*$immediate $opt_o/i ) { > $t->print($1); > last; > } >=20 > #> $t->close; > fail "failed: $opt_name - unrecognised menu response\n"; > } > } >=20 >=20 > sub action > { > # "Enter 'YES' to continue or to cancel : " > ($_) =3D $t->waitfor('/: /'); > if (! /$immediate $opt_o.*outlet $opt_n\s.*YES.*to continue/si ) { > fail "failed: $opt_name - unrecognised $opt_o response\n"; > #> $t->close; > } >=20 > # Test mode? > $t->print($opt_T?'NO':'YES'); >=20 > # "Success", "Press to continue..."=20 > ($_) =3D $t->waitfor('/continue/'); > $t->print(''); >=20 > if (defined $opt_T) { > print "success: $opt_name test outlet $opt_n $opt_o\n" unless defined= $opt_q;=20 > $t->close; > exit 0; > } elsif ( /Success/i ) { > print "success: $opt_name outlet $opt_n $opt_o\n" unless defined $opt= _q;=20 > $t->close; > exit 0; > }=20 >=20 > fail "failed: $opt_name - unrecognised action response\n"; > } >=20 >=20 > sub get_options_stdin > { > my $opt; > my $line =3D 0; > while(<>) > { > chomp; >=20 > # strip leading and trailing whitespace > s/^\s*//; > s/\s*$//; >=20 > # skip comments > next if /^#/; >=20 > $line+=3D1; > $opt=3D$_; > next unless $opt; > =20 > ($name,$val)=3Dsplit /\s*=3D\s*/, $opt; >=20 > if ( $name eq "" ) > { > print stderr "parse error: $opt_name illegal name in option $line\n"; > exit 2; > }=20 >=20 > # "node:" specified information > # TODO -- "sm" is depricated. "fm" is the prefered method > elsif ($name eq "sm" )=20 > {=20 > (my $dummy,$opt_n) =3D split /\s+/,$val; > # "node:" specified information > }=20 > elsif ($name eq "fm" )=20 > { > (my $dummy,$opt_n) =3D split /\s+/,$val; > }=20 >=20 > # "fence:" or "stomith:" specific info > elsif ($name eq "ipaddr" )=20 > { > $opt_a =3D $val; > }=20 > elsif ($name eq "login" )=20 > { > $opt_l =3D $val; > }=20 > elsif ($name eq "name" )=20 > { > $opt_name =3D $val; > }=20 > elsif ($name eq "option" )=20 > { > $opt_o =3D $val; > }=20 > elsif ($name eq "passwd" )=20 > { > $opt_p =3D $val; > }=20 > elsif ($name eq "test" )=20 > { > $opt_T =3D $val; > }=20 > elsif ($name eq "verbose" )=20 > { > $opt_v =3D $val; > }=20 >=20 > # DO NOTHING -- this field is used by fenced or stomithd > elsif ($name eq "agent" )=20 > { > }=20 >=20 > # FIXME should we do more error checking? =20 > # Excess name/vals will be eaten for now > else=20 > { > print stderr "parse error: $opt_name unknown option: $opt\n"; > #> exit 2; > } > } > } >=20 >=20 > sub telnet_error > { > fail "failed: $opt_name - telnet returned: ".$t->errmsg."\n"; > } >=20 --J2SCkAp4GZ/dPZZf Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9BgV6mC1ze528TskRAqA4AJ0V4ptF/Wqo5NZ8PepUsCSzMIFOrgCeMo89 Ds51TBx5W9RVohxMdiHtX3E= =eyO6 -----END PGP SIGNATURE----- --J2SCkAp4GZ/dPZZf--