Disk usage
[Email protected]:/data/server/spider/face question # cat 02check_disk.py
Import time
Import OS
New_time = Time.strftime ('%y-%m-%d ')
Print (New_time)
Disk_status = Os.popen (' df-h '). ReadLines ()
STR1 = ". Join (Disk_status)
With open (new_time+ '. Log ', ' W ') as F:
F.write ('%s '% str1)
F.flush ()
F.close ()
[Email protected]:/data/server/spider/face question # cat 2017-11-21.log
Filesystem Size used Avail use% mounted on
Udev 1.5G 0 1.5G 0%/dev
Tmpfs 300M 9.3M 290M 4%/run
/DEV/SDA1 21G 13G 7.5G 62%/
Tmpfs 1.5G 248K 1.5G 1%/DEV/SHM
Tmpfs 5.0M 4.0K 5.0M 1%/run/lock
Tmpfs 1.5G 0 1.5G 0%/sys/fs/cgroup
/DEV/SDB1 30G 3.1G 25G 11%/data
Tmpfs 300M 0 300M 0%/run/user/0
Tmpfs 300M 0 300M 0%/run/user/1000
Iv. generating log files for disk usage
#!/usr/bin/env python
#!coding=utf-8
Import time
Import OS
New_time = Time.strftime ('%y-%m-%d ')
Disk_status = Os.popen (' df-h '). ReadLines ()
STR1 = ". Join (Disk_status)
f = File (new_time+ '. Log ', ' W ')
F.write ('%s '% str1)
F.flush ()
F.close ()
V. How many visits per IP are counted? (Look up from the log file)
#!/usr/bin/env python
#!coding=utf-8
list = []
f = File ('/tmp/1.log ')
STR1 = F.readlines ()
F.close ()
For I in STR1:
ip = i.split () [0]
List.append (IP)
List_num = Set (list)
For J in List_num:
num = List.count (j)
Print '%s:%s '% (j,num)
This article is from the "Dream Girl" blog, please be sure to keep this source http://dreamgirl1314.blog.51cto.com/1159474/1983944
Python topic 3