Python topic 3

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.