... 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |