summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames <git@panaceas.org>2014-03-17 12:00:14 +0000
committerJames <git@panaceas.org>2014-03-17 12:00:14 +0000
commit6b8b6705d4aab6d435e89bede69db703dce0d5ff (patch)
tree3bf3d6bf5f9043c6116b5bee0d5aa30804653e79
parent7c90320682fd51130564972947a3a5924f73e301 (diff)
downloadinf-6b8b6705d4aab6d435e89bede69db703dce0d5ff.tar.gz
inf-6b8b6705d4aab6d435e89bede69db703dce0d5ff.tar.bz2
inf-6b8b6705d4aab6d435e89bede69db703dce0d5ff.zip
fish
-rwxr-xr-xinf.pl52
1 files 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 = <STDIN>;
- 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 = <STDIN>;
+ 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 );
}
}