	program drogen
	common /dddded/tmail
	integer system
	tmail=-999.
 10	continue
	call monit
        istat = system('sleep 5m')
	goto 10
	end
	


	subroutine monit
	common /dddded/tmail
	integer dstart,dunix
	character*180 line
C--
C get file from kakap
C--
	integer system
        character*250 smbcom
        character*250 smbcomp
        smbcom='smbclient \'\\\\kakap\\Ddisk\' \'BOLroom\'
     +  -U MDToper -D \'online\' -c \'get mailcheck.dat\''
        smbcomp='smbclient \'\\\\kakap\\Ddisk\' \'BOLroom\'
     +  -U MDToper -D \'online\' -c \'get glucheck.dat\''
        open(29,file='getras.exe')
        write(29,*)smbcom
        write(29,*)smbcomp
        close(29)
        istat = system('rm mailcheck.dat')
        istat = system('rm glucheck.dat')
        istat = system ('chmod +x getras.exe')
        istat = system ('getras.exe')
        istat = system
     +    ('chmod g+w mailcheck.dat')
        print *, 'smb ended with status ', istat
C--
C get parameters from file
C--
	open(37,file='mailcheck.dat')
	read(37,*,ERR=37,END=37)dstart
	read(37,*,ERR=37,END=37)tstart
        read(37,'(a)',ERR=37,END=37)line
	read(37,*,ERR=37,END=37)tsys,trasnik
 37	continue
	close(37)
C--
C get dunix tunix
C--
      istat=system(' date \'+%H\' > time.txt ')
      istat=system(' date \'+%M\' >> time.txt ')
      open(34,file='time.txt')
      read(34,*)ih
      read(34,*)im
      close(34)
      tunix=float(ih)+float(im)/60.

      istat=system(' date \'+%Y%m%d\' > datum.txt ')
C-- read date as integer
      open(34,file='datum.txt')
        read(34,*)dunix
      close(34)

C--
C first time checks
C--
C	print *,dunix,tunix,dstart,tstart
C skip if around midnigth
	if (tunix.lt.0.25) goto 999
	if (dunix.ne.dstart) goto 999
	if (tunix-tstart.gt.8.) goto 999
	ierror=0
	if (line(1:3).eq.'FAT') ierror=1
	if (line(2:4).eq.'FAT') ierror=1
	if (tunix-tsys.gt.0.5) ierror=1 
	if (ierror.eq.0) tmail=-999.
	if (ierror.eq.1 .and. tunix-tmail.gt.4) then
	  tmail=tunix
          istat = system('cat email.txt >> glucheck.dat')
          istat=system('cat glucheck.dat')
         istat=system('mail -s RASNIK_PROBLEM h73 < glucheck.dat')
C         istat=system
C     +  ('mail -s RASNIK_PROBLEM jan.spelt@nikhef.nl < glucheck.dat')
         istat=system('mail -s RASNIK_PROBLEM d65 < glucheck.dat')
C         istat=system('mail -s RASNIK_PROBLEM z66 < glucheck.dat')
C         istat=system('mail -s RASNIK_PROBLEM d90 < glucheck.dat')
	endif
 999	continue
	end
