Subversion Repositories wimsdev

Rev

Rev 2497 | Blame | Compare with Previous | Last modification | View Log | RSS feed

oldcrontab=!sh crontab -l 2>/dev/null
checkline=# Online-installed crontab
server_base=!replace internal /public_html*** by $ in $httpd_PWD***
backuper=$server_base/bin/backup
accounter=$server_base/log/account.sh

!if $oldcrontab!=$empty and $checkline notin $oldcrontab
  error=manual
  !exit
!endif

tt=!char 1 of $server_base
!if $tt!=/
 error=bad_base
 !exit
!endif

:readcron
oldcrontab=!nonempty lines $oldcrontab
n=!linecnt $oldcrontab
oldsave=
oldaccount=no
oldbackup_h=-1
oldbackup_m=
!for i=1 to $n
  l=!line $i of $oldcrontab
  l=!trim $l
  c=!char 1 of $l
  !if $c!=#
    !distribute words $l into w1,w2,w3,w4,w5,w6,w7
    !if $w3=* and $w4=* and $w5=* and $w6 iswordof \
       $backuper $accounter
      !if $w6=$backuper
        oldbackup_h=$[$w2]
        oldbackup_m=$[$w1]
      !endif
      !if $w6=$accounter
        oldaccount=yes
      !endif
    !else
      !if bin/backup notin $l and log/account.sh notin $l
        oldsave=!append line $l to $oldsave
      !endif
    !endif
  !endif
!next i


!if $job2=second and $abandon=$empty
  !bound crontab_backup_h between integer -1 and 23 default -1
  !bound crontab_backup_m between integer 0 and 59 default $[randint(59)]
  !bound crontab_account among yes,no default no
  newcron=$checkline
  !if $crontab_backup_h>=0
    newcron=$newcron\
\
# Daily backup\
$crontab_backup_m $crontab_backup_h * * * $backuper >/dev/null
  !endif
  !if $crontab_account=yes
    newcron=$newcron\
\
# Activity accounting\
16 0 * * * $accounter >/dev/null
  !endif
  newcron=$newcron\
\
# Saved from old (manual?) crontab\
$oldsave
 !sh cat >../tmp/crontab <<@\
$newcron\
@\
crontab ../tmp/crontab
  job2=
  oldcrontab=!sh crontab -l 2>/dev/null
  !goto readcron
!endif