The script is not exiting because the file does exist. If you want to see descriptive error messages, than create them:

... my $inow_fas = "/inow/index-data/sfs-fas/fas.txt"; die "Error: $inow_fas does not exist" unless ( -e $inow_fas ); print STDERR "$inow_fas: modified ", int( -M _ ), " day(s) ago\n"; ...

-derby

update:

Sorry for being curt (didn't mean to). The problem isn't your code (but it has some issues), the problem is the file does exist. As for your code, it does work but there is really no need to do all the backtick stuff - perl has builtins that can do the same thing. The plus side for the backticks is if it's what you know (shell that is), it's what you know and perl allows you to use it. The down side is all that backticking is going to fork off shell processes - that means more processes are created which ultimately means your program will take longer to run (and possibly error out if too many processes are spawned or are all ready running on your machine). Here's a slight rewrite of your snippet. I suggest you check out Effective Perl Programming - it's a great resource for learning perl idioms.

#!/usr/bin/perl -w use strict; sleep 60 while( proc_is_running( "writekeyscmdline" ) ); my $inow_fas = "fas.txt"; die "$inow_fas does not exist\n" unless (-e $inow_fas); # generate day, month, year by taking only those elements # from the array returned by localtime my( $d, $m, $y ) = (localtime(time))[3..5]; # localtime's month is zero based $m += 1; # And it's year is the number of years since 1900 $y += 1900; # no need to chomp - that just removes the trailing newline my $renamed_file = $inow_fas . $m . "-" . $d . "-" . $y; # do you really want copy, that's going to keep fas.txt around # just use the function rename. If you really want to copy, check # out CPAN's File::Copy rename( $inow_fas, $renamed_file ) or die "could not rename $inow_fas to $renamed_file\n"; sub proc_is_running{ my $program = shift; # Could use CPAN's Proc::ProcessTable but here a # system call is reasonable. Also, use absolute paths # because some cron deamons use a pared down # environment - the ps and grep it uses may # be different (PATH issues) from the ones you get when # you run the script manually - always be explicit when # running under cron return `/bin/ps -aef | /bin/grep $program | /bin/grep -v grep`; }

In reply to Re: Script doesn't exit when run from cron. by derby
in thread Script doesn't exit when run from cron. by brewmaker

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.