-
Notifications
You must be signed in to change notification settings - Fork 2
/
pwscf_log.py
60 lines (52 loc) · 1.78 KB
/
pwscf_log.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
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python
#coding:utf-8
import os
import re
import glob
import sys
import linecache
import time
def task_detail():
pw=sorted(os.popen("top -b -n 1 | grep pw.x").readlines())
user,task_name = [],[]
for i in range(0,len(pw),4):
line = re.split(r'\s+',pw[i].lstrip().rstrip())
user.append(line[1])
pid_of=os.popen("lsof -p"+line[0]+" | grep cwd").readlines()
cwd = re.split(r'\s+',pid_of[0].lstrip().rstrip())[-1]
task= re.split(r'\/',pid_of[-1].lstrip().rstrip())[-1]
#task = re.match(r"",task)
task = ".".join(re.split(r"\.",task)[:-1]) + ".in"
task_name.append(cwd+"/"+task)
return(user,task_name)
pwscf_log=open("/home/flw/pwscf_log","a")
user1,task_name1 = [],[]
while ( True ) :
(user,task_name) = task_detail()
if task_name1 == task_name :
time.sleep(60)
else :
task_name_join = "".join(task_name)
task_name1_join = "".join(task_name1)
for i,line in enumerate(task_name) :
if line in task_name1_join :
pass
else :
pwscf_log.write("-----------------------------------\n")
times=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
pwscf_log.write("At time "+ times+"\n")
pwscf_log.write(user[i] + " "+ line + " starts.\n\n\n")
for i,line in enumerate(task_name1) :
if line in task_name_join :
pass
else :
pwscf_log.write("***********************************\n")
times=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
pwscf_log.write("At time "+ times+"\n")
pwscf_log.write(user1[i] + " "+ line + " finishs.\n\n\n")
if time.strftime("%H:%M",time.localtime(time.time())) == "00:00":
times=time.strftime("%Y-%m-%d",time.localtime(time.time()))
pwscf_log.write("########## "+times+" ###################################\n\n")
pwscf_log.flush()
task_name1 = task_name
user1 = user