in reply to Script doesn't exit when run from cron.

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`; }

Replies are listed 'Best First'.
Re: Re: Script doesn't exit when run from cron.
by brewmaker (Novice) on Jan 21, 2003 at 14:35 UTC
    I just wanted to say thanks for trying. The first line of your reply says "The script is not exiting because the file does exist." This is not so.

    I purposely deleted it to test for this error condition. The script still ignores the conditional statement unless(-e $inow_fas).

    It also ignores the line die "$inow_fas does not exist\n" unless (-e $inow_fas);.

    Thanks anyway.

       -Mike