From 6b8b6705d4aab6d435e89bede69db703dce0d5ff Mon Sep 17 00:00:00 2001 From: James Date: Mon, 17 Mar 2014 12:00:14 +0000 Subject: fish --- inf.pl | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/inf.pl b/inf.pl index a9122f9..74a30b2 100755 --- a/inf.pl +++ b/inf.pl @@ -16,8 +16,8 @@ sub view($$) { exit(0); } -sub thing($$$) { - my ( $inf, $port, $thing ) = @_; +sub thing($$$$) { + my ( $inf, $port, $thing, $force ) = @_; unless ( defined $inf ) { print "No device\n"; @@ -30,15 +30,17 @@ sub thing($$$) { view( $inf, $port ) if $thing eq 'view'; - print "Are you sure you want to $thing\n"; - print "$port_name, port $port on PDU $host($name)\n"; - print "Type YES to continue\n"; - my $yes = ; - chomp $yes; + unless ( $force == 1 ) { + print "Are you sure you want to $thing\n"; + print "$port_name, port $port on PDU $host($name)\n"; + print "Type YES to continue\n"; + my $yes = ; + chomp $yes; - if ( not( $yes =~ /^yes$/i ) ) { - print "did nothing, $yes isn't yes.\n"; - exit(0); + if ( not( $yes =~ /^yes$/i ) ) { + print "did nothing, $yes isn't yes.\n"; + exit(0); + } } my $ret = undef; @@ -92,8 +94,8 @@ sub thing($$$) { } -sub thing_search($$$) { - my ( $infs, $re, $thing ) = @_; +sub thing_search($$$$) { + my ( $infs, $re, $thing, $force ) = @_; for my $h (@$infs) { my $name = $h->{host}; @@ -110,7 +112,7 @@ sub thing_search($$$) { if ( $o =~ /$re/ ) { print "Found $name, outlet $port: $o\n\n"; - thing( $inf, $port, $thing ); + thing( $inf, $port, $thing, $force ); exit(0); } } @@ -200,10 +202,11 @@ sub usage() { print "inf -s hostname -p port {-c|-o|-f|-v}\n"; print " cycle -c, turn on -o or turn off -f or view -v,\n"; print " port on switch\n"; - print "inf [-s hostname] {-c|-o|-f|-v} regexp\n"; + print "inf [-s hostname] [-F] {-c|-o|-f|-v} regexp\n"; print " cycle -c, turn on -o or turn off -f or view -v,\n"; print " the first thing found which matches regex.\n"; - print " -s limits search to only one switch\n"; + print " -s limits search to only one switch, -F doesn't\n"; + print " ask\n"; print "inf [-s hostname] -l\n"; print " show the status of switches. -s limits the output\n"; print " to one switch\n"; @@ -249,43 +252,46 @@ if ( $options->{p} ) { $port = $options->{p}; } +my $force = 0; +$force = 1 if exists $options->{F}; + if ( exists $options->{c} ) { if ( defined $port ) { - thing( INF->new( $infs->[0] ), $port, 'cycle' ); + thing( INF->new( $infs->[0] ), $port, 'cycle', $force ); exit(0); } else { - thing_search( $infs, $options->{c}, 'cycle' ); + thing_search( $infs, $options->{c}, 'cycle', $force ); } } if ( exists $options->{o} ) { if ( defined $port ) { - thing( INF->new( $infs->[0] ), $port, 'on' ); + thing( INF->new( $infs->[0] ), $port, 'on', $force ); exit(0); } else { - thing_search( $infs, $options->{o}, 'on' ); + thing_search( $infs, $options->{o}, 'on', $force ); } } if ( exists $options->{f} ) { if ( defined $port ) { - thing( INF->new( $infs->[0] ), $port, 'off' ); + thing( INF->new( $infs->[0] ), $port, 'off', $force ); exit(0); } else { - thing_search( $infs, $options->{f}, 'off' ); + thing_search( $infs, $options->{f}, 'off', $force ); } } if ( exists $options->{v} ) { if ( defined $port ) { - thing( INF->new( $infs->[0] ), $port, 'view' ); + thing( INF->new( $infs->[0] ), $port, 'view', $force ); exit(0); } else { - thing_search( $infs, $options->{v}, 'view' ); + thing_search( $infs, $options->{v}, 'view', $force ); } } -- cgit v1.2.3