Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl script failing from crontab
    primarykey
    data
    text
    <p>I have a perl script that reads our firewall access logs to see who has used a specific vpn account. This works fine when run from the command line, but fails when run from crontab. The code is here</p> <pre><code>#!/usr/bin/perl -w use strict; use warnings; use MIME::Lite::TT::HTML; my $basedir = "/var/log"; my @verdir = qw(fw_d); my $fulldir; my $configs; my $combidir; my @results; my @files1; foreach $combidir (@verdir) { $fulldir = "$basedir/$combidir"; opendir (DIR, $fulldir); my @files = grep { $_ ne '.' &amp;&amp; $_ ne '..' &amp;&amp; $_ ne 'CVS' } readdir DIR; closedir (DIR); @files1 = sort {expand($a)cmp expand($b)}(@files); foreach my $configs (@files1) { my $now = time; my @stat = stat("$fulldir/$configs"); if ($stat[9] &gt; ($now - 2592000)) { system("/usr/bin/less -f $fulldir/$configs | /bin/grep NETOPS_TUNNEL &gt;&gt; /usr/local/CCS/ravpn/output.log"); } } } results(); sendmailnew(\@results); sub results{ my $input = "/usr/local/CCS/ravpn/output.log"; open my $fh, "&lt;", "$input" or die "could not open '$input': $!"; while (&lt;$fh&gt;){ if ($_ =~ /(................)fw.*(Group = NETOPS_TUNNEL). (Username = .(authenticated.)/){ push (@results, "$1 $2 $3 $4&lt;br&gt;") } } return @results } sub expand { my $file=shift; $file=~s{(\d+)}{sprintf "%04d", $1}eg; # expand all numbers to 4 digits return $file; } sub sendmailnew { my %params; my @results = @{$_[0]}; $params{sorted} = "@results"; my %options; $options{INCLUDE_PATH} = '/usr/local/CCS/ravpn/templates/'; my $msg = MIME::Lite::TT::HTML-&gt;new( From =&gt; "", #To =&gt; "", BCC =&gt; "", Subject =&gt; "", Encoding =&gt; 'quoted-printable', Template =&gt; { text =&gt; 'test.txt.tt', html =&gt; 'sort.html.tt', }, TmplOptions =&gt; \%options, TmplParams =&gt; \%params, ); $msg-&gt;send; system("rm -rf /usr/local/CCS/ravpn/output.log"); } </code></pre> <p>When this is run from the command line, it goes to the directory /var/log/fw_d, gets all entries that are less than 30 days old, and passes them to have less and grep run against them, the results are outputted to output.log. (this file is created when it is run via crontab, but nothing is ever outputted). When run from the command line, entries are added to the output.log</p> <p>Once the output.log is created, that is scanned for a specific set of items, and the results are pushed into an array called results, which is then emailed out.</p> <p>This script works great if run manually, but if run from crontab, either the user we use to create the logs, or the root user, it fails to output anything to the output.log file.</p> <p>I have a feeling its going to be something simple, but im not sure.</p> <p>this is the crontab -e entry</p> <pre><code> 40 03 * * * perl /usr/local/CCS/ravpn/ravpn.pl </code></pre> <p>The files that are being read are either plain text, or zipped text files, .gz, so i needed a way of reading them without unzipping hence the use of less.</p> <p>Any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload