-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckffb.py
47 lines (42 loc) · 1.47 KB
/
checkffb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import subprocess
import os
import time
import sys
import datetime
def gethosts(queue):
openhosts = []
otherhosts = []
result = subprocess.check_output('/opt/slurm/slurm-curr/bin/sinfo -N -p %s'%queue, shell=True).decode('utf-8')
for line in result.split('\n')[1:]:
if ' idle' in line or ' alloc' in line or ' mix' in line or ' drain' in line or ' down' in line:
fields = line.split()
if len(fields) == 0: continue
if ' drain' not in line and ' down' not in line:
openhosts.append(fields[0])
else:
otherhosts.append(fields[0])
openhosts.sort()
otherhosts.sort()
return openhosts,otherhosts
fname='/sdf/data/lcls/drpsrcf/ffb/test/psana_batch/e307-r0999-s00-c00.xtc'
openhosts,otherhosts = gethosts('milano')
nerr=0
msg=''
for nhost,host in enumerate(openhosts):
cmd = 'ssh %s ls %s'%(host,fname)
try:
result = subprocess.check_output(cmd, shell=True).decode('utf-8')
#print('****',host,result)
except:
nerr+=1
msg+='*ERR %s\n'%host
msg+='*** Summary: found %d nodes with %d errors\n'%(len(openhosts),nerr)
from email.mime.text import MIMEText
from subprocess import Popen, PIPE
mailmsg = MIMEText(msg)
mailmsg["From"] = "[email protected]"
import getpass
mailmsg["To"] = getpass.getuser()+"@slac.stanford.edu"
mailmsg["Subject"] = "ffb test"
p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE)
p.communicate(mailmsg.as_string().encode())