Welcome to Perl and the Monastery, PerlMonger79!

My experience with cron has been that the safest thing to do is always use absolute pathnames for everything in the crontab and everything that is run from the crontab, which is basically also what Paladin meant with the CWD issue. In this case, I think it's unlikely that anything is affected by %ENV variables, but it's important to keep it in mind.

In this case, the first thing that jumps out at me is that you're not checking the chdir for errors, as in e.g. chdir "/path/to/directory" or die "chdir: $!";

Although not critical, there are several other suggestions I'd make:

Here's a script reworked with several of those suggestions:

#!/usr/bin/perl use warnings; use strict; use Time::Piece; use File::Spec::Functions qw/catfile/; use IO::Compress::Zip qw/zip $ZipError/; # Timestamp my $now = localtime; $now -= 60*60; $now = $now->strftime("%d%b%Y_%H00"); # Where zip file is to be stored my $arc = catfile("/path/to/archive","$now.zip"); die "Error: $arc already exists, refusing to overwrite" if -e $arc; # Where csv files are found. chdir "/path/to/directory" or die "chdir: $!"; # Zipping files found and storing into archive my @files = glob("*-$now.csv"); warn "Warning: No files to ZIP found\n" unless @files; zip \@files => $arc or die "Cannot create zip file: $ZipError" ; # Deleting csv files unlink(@files)==@files or warn "Failed to unlink some files: $!";

Update: A few grammar improvements. Apparently I work for the Department of Redundancy Department, apparently.


In reply to Re^3: Zip script not running on cron by haukex
in thread Zip script not running on cron by PerlMonger79

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.