Article 6Q596 [SOLVED] Perl script "logviewer" broken

[SOLVED] Perl script "logviewer" broken

by
james000
from LinuxQuestions.org on (#6Q596)
Hi,
I had one logger server (all clients forward logs with syslog to this server) on RHEL 7.9. That was dead and I had to rebuilt it. Now one application user reported that one of their perl script is not working. Probably it is looking for some packages to be installed, but I can't figure, what to be installed.
Here is example from working server -
Code:[root@working-server ~]# logview
no file specified at /usr/local/bin/logview line 47, <DATA> line 12.
[root@working-server ~]#Here is broken example, and that script -
Code:[root@broken-server ~]# logview
Can't locate File/Tail.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/bin/logview line 5.
BEGIN failed--compilation aborted at /usr/local/bin/logview line 5.
[root@broken-server ~]# which logview
/usr/local/bin/logview
[root@broken-server ~]# cat /usr/local/bin/logview
#!/usr/bin/perl

use strict;
use warnings;
use File::Tail;
use POSIX qw(strftime);
use Getopt::Std;

my %format = (
normal => "\033[0m",
red => "\033[1;31m",
green => "\033[1;32m",
yellow => "\033[1;33m",
blue => "\033[1;34m",
magenta => "\033[1;35m",
cyan => "\033[1;36m",
);

my $localrc = "$ENV{HOME}/.logviewrc";
my %macros = ();

my %opt;
getopts("Mc:fms:g:v:X", \%opt) or die usage();

##
## Read in config files
##

parse_rc(\*DATA);
foreach my $rc (($localrc, $opt{c})) {
if (defined($rc) && open(RC, "<$rc")) {
parse_rc(\*RC);
close(RC);
}
}

## Print macros & exit if requested
if ($opt{M}) {
foreach my $macro (sort keys %macros) {
printf("%-20s %-50s\n", $macro, $macros{$macro});
}
exit 0;
}

## Finish reading command-line
my $file = shift @ARGV;
die "no file specified" unless $file;

my $file_template;
if ($opt{m}) {
die "Unknown macro $file\n" unless defined $macros{$file};
$file_template = $macros{$file};
$file = decode_file();
}
elsif ($opt{s}) {
$file_template = $file;
$file = decode_file();
}

##
##
##

my $tail = "";
if ( $opt{f} ) {
$tail = tie *FILE, "File::Tail", (
name => $file,
ignore_nonexistant => 1,
maxinterval => 3,
interval => 1,
adjustafter => 2,
);
if ($opt{m} || $opt{s}) {
$tail->name_changes(\&decode_file)
}
}
else {
open(FILE, $file) or die "Unable to open file $file: $!\n";
}

##
## start reading from the file...
##

LINE: while (<FILE>) {

## Filter lines
if ($opt{'g'}) {
my $regex = $opt{'g'};
next LINE if $_ !~ /$regex/;
}
if ($opt{'v'}) {
my $regex = $opt{'v'};
next LINE if $_ =~ /$regex/;
}

if ($opt{X}) {
s/^(\w{3} .\d \d\d:\d\d:\d\d) ([\w-]+) /$1 $format{green}$2$format{norm al} /;
s/ (XY \d+) / $format{yellow}$1$format{normal} /;
}

## We got here, so print the line
print $_;
}

####
#### subroutines
####
sub decode_file {
return strftime($file_template, localtime(time));
}

sub usage {
return <<EOF;
Usage: $0 -f|-m|-s [-c config] [-g regex] [-v regex] file
$0 -M|-h
-f emulate a "tail -f" on file
-m Treat file as a macro (use -M to see macros). Implies -s
-s Apply strftime % substitions to file
-g regex only show lines matching regex
-v regex omit lines matching regex
-c config config file to read (after /usr/local/etc/logtail.conf
and $ENV{HOME}/.logtail.conf
-M Display defined macros
-h Print this help and exit

Note that regexs are perl-style, and should not include the '//' characters
EOF
}

sub parse_rc {
my $file = shift @_;

while (<$file>) {
chomp;
next if /^\s*(#.*)?$/;
if (/^\s*macro\s+(\S+)\s*=\s*(\S+)$/) {
$macros{$1} = $2;
}
}
}

__DATA__

macro messages = /var/adm/messages
macro auth = /var/log/authlog

macro v911-app = /logs/v911/app/%Y/%m/%d/%H.log
macro v911-auth = /logs/v911/sys/%Y/%m/%d/auth.log
macro v911-daemon = /logs/v911/sys/%Y/%m/%d/daemon.log
macro v911-kern = /logs/v911/sys/%Y/%m/%d/kern.log
macro v911-mail = /logs/v911/sys/%Y/%m/%d/mail.log

[root@broken-server ~]#This server is not open to internet, but internal repo server is configured
Code:[root@broken-server ~]# yum repolist
Loaded plugins: enabled_repos_upload, langpacks, package_upload, product-id, search-disabled-repos, subscription-manager
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
repo id repo name status
!rhel-7-server-rpms/7Server/x86_64 Red Hat Enterprise Linux 7 Server (RPMs) 33,463
!rhel-7-server-satellite-tools-6.9-rpms/x86_64 Red Hat Satellite Tools 6.9 (for RHEL 7 Server) (RPMs) 71
repolist: 33,534
Uploading Enabled Repositories Report
Loaded plugins: langpacks, product-id, subscription-manager
[root@broken-server ~]#Looks like it is complaining on Quote:
use File::Tail;
. Our servers are not open to internet. Is it possible to get it from local redhat repo or if I can download from internet ?

Can someone help me to point, what package should I install on this server to make perl run, as per the error mentioned above ?

Thanks
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments