At 07.00 -0500 1999.02.16, Sean Carte wrote: >Is it possible to use MacPerl to implement cron-like features on a Mac? Yes. Might be better to use an exteranl Cron, though. >I've used Frontier to do this in the past, but would like to use MacPerl >instead. All I've been able to find that's relevant is the sleep() >function, but this seems to tie up the Mac. My idea is to periodically >close files in order to back them up and then reopen them. I was using the script below for awhile. I saved it as a runtime and left it in my MacPerl folder. Worked OK. I haven't used it in awhile and don't know what bugs may remain. I use sleep(), and I don't know why it would tie up your Mac. I don't even remember why I did everything I did below. Oh well. :) As input to the cron program, I had folder called Cron Preferences in the System Folder. Each item was a text file with a MacPerl script in it, and was named in a cron-like way: * * * * * SetHeads run every minute 6 16 * * * books.plx run every day at 0616 hrs etc. Basically, I used the same setup as used in the Cron program for Mac that I sometimes use. >I'm sorry if this has been covered before; I seem to remember something >on this topic. By the way, is there an archive for this mailing list? Yes. See http://www.ptf.com/macperl/ for a list of resources. #!perl # crond by pudge@pobox.com 1998.07.07 use strict; use Mac::Files; use Time::Local; use IO::Tee; # I don't recall if this is the same IO::Tee on CPAN my($dir, $log, %files, @files); $dir = FindFolder(kOnSystemDisk(), kPreferencesFolderType()) . ':Cron Preferences:'; $log = "${dir}log"; _init(); while (1) { my @time = localtime; @files = (); FILES: for my $file (keys %files) { my @nums = @{$files{$file}}; for my $x (1 .. 4, 6) { if ($nums[$x] =~ /^(\d+)-?(\d+)?$/) { my $c; for ($1 .. $2 || $1) {$c++ if $_ == $time[$x]} next FILES if !$c; } } push @files, $file; } for my $file (@files) { print "[${\(scalar localtime)}]"; printf " $files{$file}[7] ... %s", do $file ? 'Done.' : "can't do $file:\n $!"; } if ((localtime)[1] != $time[1]) { $time[1]++; @files = (); print "Redo"; do FILES; } sleep(61-(localtime)[0]); } sub _init { open(STDERR, ">&STDOUT") or die $!; open(LOG, ">>$log") or die $!; tie(*TEE, q(IO::Tee), *STDOUT, *LOG); select(TEE); $| = 1; $\ = "\n"; printf "\n\nStarting at [${\(scalar localtime)}] ...\n"; %files = (); opendir(D, $dir) or die $!; foreach my $file (sort readdir D) { if ($file =~ /^([0-9-]+|\*)\s+([0-9-]+|\*)\s+([0-9-]+|\*)\s+([0-9-]+|\*)\s+([0-9-]+|\*)\s+(.* )$/) { $files{"${dir}$file"} = [$file, $1, $2, $3, $4, undef, $5, $6]; print $file; } } closedir(D); END {print "\nLog closed at [${\(scalar localtime)}]"} } -- Chris Nandor mailto:pudge@pobox.com http://pudge.net/ %PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10 1FF77F13 8180B6B6']) ***** Want to unsubscribe from this list? ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch