前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python 题目3

python 题目3

作者头像
py3study
发布2020-01-03 16:09:51
4260
发布2020-01-03 16:09:51
举报
文章被收录于专栏:python3python3

磁盘使用情况

root@ubuntu:/data/server/spider/面试题# 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()

root@ubuntu:/data/server/spider/面试题# 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

四、生成磁盘使用情况的日志文件

#!/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()

五、统计出每个IP的访问量有多少?(从日志文件中查找)

#!/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)

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档