;
;+
;NAME:
;	kill_ftp
;PURPOSE:
;	To monitor FTP jobs that have hung up and are eating up CPU
;HISTORY:
;	Written 13-Sep-93 by M.Morrison
;	19-Oct-93 (MDM) - Modified how ftp jobs were recognized
;       18-Mar-94 (SLF) - Trained to kill
;-
;
;software   855  0.0  0.0  352   60 ?  IW     0:00 csh -c ftp -n < $ys/site/script/nobeyama.ftp
;software   858 58.3  0.6  260   68 ?  R N  1370:53 ftp -n
;software 12704  0.0  0.0  352   60 ?  IW     0:00 csh -c ftp -n < $ys/site/script/nobeyama.ftp
;software 12706  0.0  0.0  280   32 ?  IW     0:00 ftp -n

cmd = 'ps -auxw'
spawn, cmd, result
;
pp = strpos(result, 'ftp ')
ss = where(pp ne -1)
;
if (ss(0) eq -1) then begin
    message, 'No FTP jobs running'
    return
end
;
list = result(ss)
for i=0,n_elements(list)-1 do begin
    rr = strcompress(result(ss(i)))
    print, 'CHECKING: ' + rr

    arr = str2arr(rr, delim = ' ')
    ip = where(strpos(arr, ':') ne -1)
    temp = arr(ip(0))
    p = strpos(temp, ':')
    t1 = fix(strmid(temp, 0, p))
    ;
    killit=1
    killcmd = 'kill -9 ' + arr(1)
    node=get_host()
    if (t1 gt 50) then begin
        if killit then begin
	   spawn,killcmd,spawnout
           message = ['KILL_FTP Message', $
	      'I am killing the following process on machine '  + node, rr]
           subject='FTP JOB KILLED'
        endif else begin
	   message = ['KILL_FTP Message', $
		'FTP process probably needs to be killed on ' + get_host(), $
		'KILL_FTP currently does not kill automatically.  Please do it for me', $
		'  ', $
		rr]
	    print, '***** Needs to be killed'
        endelse
	mail, message, user='software@isass0', subj=subject
    end else begin
	print, '***** Not eating CPU.  Does not have to be killed'
    end
end

end

