diff options
author | John Southworth <john.southworth@vyatta.com> | 2011-09-15 16:51:05 -0700 |
---|---|---|
committer | John Southworth <john.southworth@vyatta.com> | 2011-10-27 17:11:29 -0500 |
commit | b04673afd899d2032200799a9d9b0c72901ad262 (patch) | |
tree | cdc31bc0d25a189341aa31facfa678120650d7e5 /scripts | |
parent | 5abab7cc94b1eb8784a34c5efd0a1a685979630d (diff) | |
download | vyatta-op-b04673afd899d2032200799a9d9b0c72901ad262.tar.gz vyatta-op-b04673afd899d2032200799a9d9b0c72901ad262.zip |
More monitor interface traffic commands
(cherry picked from commit 3358412ae5e8d7ba94aedeb78080d2509d82239f)
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/vyatta-monitor-cleanup | 2 | ||||
-rwxr-xr-x | scripts/vyatta-tshark.pl | 103 |
2 files changed, 104 insertions, 1 deletions
diff --git a/scripts/vyatta-monitor-cleanup b/scripts/vyatta-monitor-cleanup index cd08cbc..553c1f8 100644 --- a/scripts/vyatta-monitor-cleanup +++ b/scripts/vyatta-monitor-cleanup @@ -4,7 +4,7 @@ declare CURRENT_UID=$(id -u) declare CURRENT_UNAME=$(id -un) declare -a MPIDS MODE=$1 -MPIDS=( $(ls /var/run/vyatta/monitor/*.pid) ) +MPIDS=( $(ls /var/run/vyatta/monitor/*.pid 2> /dev/null ) ) for pidfile in "${MPIDS[@]}"; do pid=$(<$pidfile) diff --git a/scripts/vyatta-tshark.pl b/scripts/vyatta-tshark.pl new file mode 100755 index 0000000..103808d --- /dev/null +++ b/scripts/vyatta-tshark.pl @@ -0,0 +1,103 @@ +#!/usr/bin/perl +# +# Module: vyatta-tshark-interface-port.pl +# +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# 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. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2006, 2007, 2008 Vyatta, Inc. +# All Rights Reserved. +# +# Author: John Southworth +# Date: Sept. 2011 +# Description: run tshark on a given interface with options +# +# **** End License **** +# + +use lib "/opt/vyatta/share/perl5/"; + +use strict; +use warnings; +use Getopt::Long; + +sub check_if_interface_is_tsharkable { + my $interface = shift; + + my @grep_tshark_interfaces = `sudo /usr/bin/tshark -D | grep $interface`; + my $any_interface; + + for my $count (0 .. $#grep_tshark_interfaces) { + my @temp = split(/ /,$grep_tshark_interfaces[$count]); + chomp $temp[1]; + $grep_tshark_interfaces[$count] = $temp[1]; + } + + my $exact_match = 0; + for my $count (0 .. $#grep_tshark_interfaces) { + if ($grep_tshark_interfaces[$count] eq $interface) { + $exact_match = 1; + $any_interface = $grep_tshark_interfaces[$count]; + } + } + if ($exact_match == 0 || $any_interface eq 'any') { + print "Unable to capture traffic on $interface\n"; + exit 1; + } +} + +# +# main +# +my ($detail,$filter,$intf,$unlimited); + +GetOptions("detail!" => \$detail, + "filter=s" => \$filter, + "intf=s" => \$intf, + "unlimited!" => \$unlimited); + +check_if_interface_is_tsharkable($intf); + +if (defined($filter)) { + if (defined($detail)) { + if (defined($unlimited)){ + print "Capturing traffic on $intf ...\n"; + exec "sudo /usr/bin/tshark -n -i $intf -V $filter 2> /dev/null"; + } else { + print "Capturing traffic on $intf ...\n"; + exec "sudo /usr/bin/tshark -n -i $intf -c 1000 -V $filter 2> /dev/null"; + } + } elsif (defined($unlimited)) { + print "Capturing traffic on $intf ...\n"; + exec "sudo /usr/bin/tshark -n -i $intf $filter 2> /dev/null"; + } else { + print "Capturing traffic on $intf ...\n"; + exec "sudo /usr/bin/tshark -n -i $intf -c 1000 $filter 2> /dev/null"; + } +} elsif (defined($detail)) { + if (defined($unlimited)) { + print "Capturing traffic on $intf ...\n"; + exec "sudo /usr/bin/tshark -n -i $intf -V 2> /dev/null"; + } else { + print "Capturing traffic on $intf ...\n"; + exec "sudo /usr/bin/tshark -n -i $intf -c 1000 -V 2> /dev/null"; + } +} elsif (defined($unlimited)) { + print "Capturing traffic on $intf ...\n"; + exec "sudo /usr/bin/tshark -n -i $intf 2> /dev/null"; +} else { + print "Capturing traffic on $intf ...\n"; + exec "sudo /usr/bin/tshark -n -i $intf -c 1000 2> /dev/null"; +} + +exit 0; + +#end of file |