diff --git a/files/sbin/puplast b/files/sbin/puplast new file mode 100755 index 0000000..72e80a3 --- /dev/null +++ b/files/sbin/puplast @@ -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=; 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 diff --git a/files/sbin/puplog b/files/sbin/puplog index bcb33c2..91b8e1f 100755 --- a/files/sbin/puplog +++ b/files/sbin/puplog @@ -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=; 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 diff --git a/files/sbin/puplog.pl b/files/sbin/puplog.pl new file mode 100755 index 0000000..ac31b1b --- /dev/null +++ b/files/sbin/puplog.pl @@ -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 = ) { + 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 diff --git a/files/sbin/puptail b/files/sbin/puptail new file mode 100755 index 0000000..bcb33c2 --- /dev/null +++ b/files/sbin/puptail @@ -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 diff --git a/files/sbin/rkwarnings b/files/sbin/rkwarnings index c12b577..87798b4 100755 --- a/files/sbin/rkwarnings +++ b/files/sbin/rkwarnings @@ -14,7 +14,7 @@ SCRDIR = File.dirname( $0 ) debug = 0 verbose = 0 -ERRORS = 0 +errors = 0 VERSION = '$Revision: 24951 $' opts = GetoptLong.new( @@ -79,6 +79,7 @@ else end myos=`facter osfamily` +myos.chomp! case myos when 'Debian' @@ -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) @@ -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