home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
182.lha
/
ARexxCron
/
RXCron.rex
< prev
next >
Wrap
OS/2 REXX Batch file
|
1988-04-28
|
3KB
|
81 lines
/* RXCron: a "cron" program for the ARexx (1.06+) environment. *
* Version 0.2 10-10-88 Author: Robert Rethemeyer (@BBS-JC) *
* Status: PUBLIC DOMAIN, offered "as-is" (no warranties, etc.) *
* Format: "RXCRON [cronfile]" to run the program *
* "RXCRON -k" to kill it *
*/
runprog="runwsh >nil:" /* or RUN or ARUN */
arg cfile
select
when cfile="?" then do
say sourceline(4)||sourceline(5); exit; end
when cfile="-K" then do
call setclip("rxckill",1)
say "Be patient... RXCron will terminate within one minute"
exit; end
otherwise do
if cfile="" then cfile="s:crontab"
if ~exists(cfile) then do; say "RXCron can't find" cfile; exit 20; end
end
end
call setclip("rxckill","00")
DO FOREVER
if getclip("rxckill") then do; say "RXCron terminated." ; exit ; end
parse value statef(cfile) with a b c d e t1 t2 /* if file time stamp has */
tstamp=t1||t2 /* changed, reread the file */
if tstamp~=ostamp then do;
if ~open(cron,cfile,'R') then exit 21
do n=1 until eof(cron)
cline.n = readln(cron)
if eof(cron) then leave
cline.n=translate(cline.n," ",'09'x) /* removes tabs */
parse value cline.n with cmin.n chr.n cday.n cmon.n cwd.n cmd.n
end
n=n-1
call close cron
say "RXCron found" n "entries in new" cfile
if n=0 then exit 22
ostamp=tstamp
end
t=time() ; d=date("U") /* get current date&time */
hr =substr(t,1,2) ; min=substr(t,4,2) ; mon=substr(d,1,2) ; day=substr(d,4,2)
wd=(index("xSuMoTuWeThFrSa",substr(date("W"),1,2))/2)-1
do x=1 to n
if cline.x = "" then iterate x
if ~match(mon,cmon.x) then iterate x
if ~match(wd,cwd.x) then iterate x
if ~match(day,cday.x) then iterate x
if ~match(hr,chr.x) then iterate x
if ~match(min,cmin.x) then iterate x
say "RXCron @" mon||"/"||day hr||":"||min "->" cmd.x
runprog cmd.x
end
call delay 50*(60-substr(time(),7,2)) /* wait until next minute */
END; exit /* end of main program */
/* Match... matches numbers with crontab specifications */
Match: /* PROCEDURE returns boolean */
arg aa,bb
k=verify("*,-0123456789",bb,"M")
select
when k=0 then do; say "RXCron detected bad number/expr:" bb; exit 11; end
when k=1 then return 1 /* splat */
when k=2 then do /* comma */
w=translate(bb," ",",")
do m=1 to words(w)
if aa=word(w,m) then return 1
end
return 0
end
when k=3 then do /* dash */
w=translate(bb," ","-")
p=word(w,1); q=word(w,2)
if aa>=p & aa<=q then return 1; else return 0
end
otherwise if aa=bb then return 1; else return 0
end
exit 23 /* should never get here */