#!/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`; }