Skip to content

Commit

Permalink
merged development updates
Browse files Browse the repository at this point in the history
  • Loading branch information
qs5779 committed Oct 22, 2018
2 parents 8773255 + 1d0d595 commit a27396e
Show file tree
Hide file tree
Showing 5 changed files with 312 additions and 8 deletions.
84 changes: 84 additions & 0 deletions files/sbin/puplast
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
# -*- Mode: Bash; tab-width: 2; indent-tabs-mode: nil -*- vim:sta:et:sw=2:ts=2:syntax=sh
# Revision History:
# 20180811 - que - initial version
#

SCRIPT=$(basename "$0")
VERSION='$Revision: 1.0.0 $' # will be replaced by svn commit # if using subversion with Revision keywords on
VERBOSE=0
DEBUG=0
ERRORS=0
LAST=1
LFN=''

function usage {
cat << EOM
usage: $SCRIPT [-a] [-d] [-h] [-l log] [-v] [-V]
where:
-a show all
-d specify debug mode
-h show this message and exit
-v add verbosity
-V show version and exit
EOM
exit 1
}

while getopts ":adhl:vV" opt
do
case "$opt" in
a ) LAST=0 ;;
d )
((DEBUG+=1))
((VERBOSE+=1))
;;
h )
usage
;;
l )
LFN="$OPTARG"
;;
v ) ((VERBOSE+=1)) ;;
V )
echo "$SCRIPT VERSION: $(echo $VERSION | awk '{ print $2 }')"
exit 0
;;
* )
echo "Unexpected option \"$opt\""
usage
;;
esac
done
shift $((OPTIND - 1))

if [ -z "$LFN" ]
then
case "$(facter osfamily)" in
Debian )
LFN=/var/log/syslog
;;
* )
LFN=/var/log/messages
;;
esac
fi

if [ -r "$LFN" ]
then
SUDO=''
else
SUDO=sudo
fi

if [ $LAST -ne 0 ]
then
PID=$($SUDO tac "$LFN" | grep 'puppet-agent' | head -1 | perl -e '$v=<STDIN>; if($v=~/\[(\d+)\]:/) { printf "$1\n"; }')

$SUDO tac "$LFN" | grep "puppet-agent\[$PID\]:" | tac
else
$SUDO grep 'puppet-agent' "$LFN"
fi

# ERRORS=$((ERRORS+=1)) # darn ubuntu default dash shell
exit $ERRORS
13 changes: 10 additions & 3 deletions files/sbin/puplog
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,18 @@ else
SUDO=sudo
fi

if [ $LAST -ne 0 ]
if [ -f "$LFN" ]
then
$SUDO tac "$LFN" | grep 'puppet-agent' | sed -E '/Using configured environment|Starting Puppet client version/q' | tac
if [ $LAST -ne 0 ]
then
PID=$($SUDO tac "$LFN" | grep 'puppet-agent' | head -1 | perl -e '$v=<STDIN>; if($v=~/\[(\d+)\]:/) { printf "$1\n"; }')
$SUDO tac "$LFN" | grep "puppet-agent\[$PID\]:" | tac
else
$SUDO grep 'puppet-agent' "$LFN"
fi
else
$SUDO grep 'puppet-agent' "$LFN"
echo "File not found: $LFN" >&2
((ERRORS+=1))
fi

# ERRORS=$((ERRORS+=1)) # darn ubuntu default dash shell
Expand Down
137 changes: 137 additions & 0 deletions files/sbin/puplog.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/usr/bin/perl -w
# -*- Mode: Perl; tab-width: 2; indent-tabs-mode: nil -*- vim:sta:et:sw=2:ts=2:syntax=perl
#
# Revision History:
# 20180818 - whoami - initial version
#

use strict;
use File::Basename qw/ basename dirname /;
use Getopt::Long;
use Pod::Usage;
use File::Temp qw/ :POSIX /;

use constant TRUE => 1;
use constant FALSE => 0;

my $SCRIPT = basename( "$0" );
my $SCRDIR = dirname("$0");

my $debug = 0;
my $verbose = 0;
my $man = 0;
my $help = 0;
my $version = 0;
my $error_count = 0;

Getopt::Long::Configure("bundling");

GetOptions(
'd|debug+' => \$debug,
'v|verbose+' => \$verbose,
'V|Version' => \$version,
'man' => \$man,
'h|help|?' => \$help
) or pod2usage( 2 );

pod2usage( 1 ) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;

my $VERSION = '$Revision: 990 $';

if ( $version ) {
$VERSION =~ s/\$//g;
print "$SCRIPT $VERSION\n";
exit(0);
}

my $lfn;

my $scratch = qx(grep ID_LIKE /etc/os-release);

if ($scratch =~ m/debian/i) {
$lfn = '/var/log/syslog';
}
else {
$lfn = '/var/log/messages';
}


my $tac;
if(! -r $lfn) {
$tac = 'sudo tac';
}
else {
$tac = 'tac';
}

my ($fh, $file) = tmpnam();

open(LOG, "$tac '$lfn'|") or die(sprintf("Failed to open pipe for command 'tac %s'\n", $lfn));

my $line;
my $hits = 0;
my ($lead, $pid);
my $print = 0;

while ($line = <LOG>) {
if ($line =~ /^([^:]).*puppet-agent\[(\d+)\]: Applied catalog/) {
$lead = $1;
$pid = $2;
if($hits > 0) {
close($fh);
system(sprintf("tac %s", $file));
cleanexit();
}
else {
$hits++;
$print = 1;
}
}
elsif($hits > 0 && $line =~ /^${lead}.*puppet-agent\[${pid}\]:/) {
print $fh $line;
}
print $fh $line if($print);
}

exit($error_count);

sub cleanexit {
close(LOG);
exit($error_count);
}

__END__
=head1 NAME
perl-script-template.pl - example perl script template
=head1 SYNOPSIS
perl-script-template.pl [-d] [-h] [-v] [-V]
example perl script template
=head1 OPTIONS
=over 8
=item B<-d|--debug>
Sets debug flag to show more output.
=item B<-h|--help>
Print a brief help message and exits.
=item B<-v|--verbose>
Sets verbose flag to show more output.
=item B<-V|--version>
Prints version and exits
=back
75 changes: 75 additions & 0 deletions files/sbin/puptail
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
# -*- Mode: Bash; tab-width: 2; indent-tabs-mode: nil -*- vim:sta:et:sw=2:ts=2:syntax=sh
# Revision History:
# 20180811 - que - initial version
#

SCRIPT=$(basename "$0")
VERSION='$Revision: 1.0.0 $' # will be replaced by svn commit # if using subversion with Revision keywords on
VERBOSE=0
DEBUG=0
ERRORS=0
LAST=0

function usage {
cat << EOM
usage: $SCRIPT [-d] [-h] [-l] [-v] [-V]
where:
-d specify debug mode
-h show this message and exit
-l show last (most recent) run only
-v add verbosity
-V show version and exit
EOM
exit 1
}

while getopts ":dhlvV" opt
do
case "$opt" in
d )
((DEBUG+=1))
((VERBOSE+=1))
;;
h )
usage
;;
l ) ((LAST+=1)) ;;
v ) ((VERBOSE+=1)) ;;
V )
echo "$SCRIPT VERSION: $(echo $VERSION | awk '{ print $2 }')"
exit 0
;;
* )
echo "Unexpected option \"$opt\""
usage
;;
esac
done
shift $((OPTIND - 1))

case "$(facter osfamily)" in
Debian )
LFN=/var/log/syslog
;;
* )
LFN=/var/log/messages
;;
esac

if [ -r "$LFN" ]
then
SUDO=''
else
SUDO=sudo
fi

if [ $LAST -ne 0 ]
then
$SUDO tac "$LFN" | grep 'puppet-agent' | sed -E '/Using configured environment|Starting Puppet client version/q' | tac
else
$SUDO grep 'puppet-agent' "$LFN"
fi

# ERRORS=$((ERRORS+=1)) # darn ubuntu default dash shell
exit $ERRORS
11 changes: 6 additions & 5 deletions files/sbin/rkwarnings
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SCRDIR = File.dirname( $0 )
debug = 0
verbose = 0

ERRORS = 0
errors = 0
VERSION = '$Revision: 24951 $'

opts = GetoptLong.new(
Expand Down Expand Up @@ -79,6 +79,7 @@ else
end

myos=`facter osfamily`
myos.chomp!

case myos
when 'Debian'
Expand All @@ -102,7 +103,7 @@ end

if File.exists?(rkhlog)
if ! File.readable?(rkhlog)
system("chgrp #{wheel} #{rkhlog}")
system("sudo chgrp #{wheel} #{rkhlog} ; sudo chmod g+r #{rkhlog}")
end

if File.readable?(rkhlog)
Expand Down Expand Up @@ -131,14 +132,14 @@ if File.exists?(rkhlog)
end
else
STDERR.puts "File not readable: #{rkhlog}"
ERRORS += 1
errors += 1
end

else
STDERR.puts "File not found: #{rkhlog}"
ERRORS += 1
errors += 1
end

exit ERRORS
exit errors


0 comments on commit a27396e

Please sign in to comment.