-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
312 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters