python 题目3

简介:

磁盘使用情况

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)



本文转自 xxl714 51CTO博客,原文链接:http://blog.51cto.com/dreamgirl1314/1983944,如需转载请自行联系原作者

相关文章
|
3月前
|
SQL 数据采集 算法
LeetCode 题目 66:加一【python5种算法实现】
LeetCode 题目 66:加一【python5种算法实现】
|
3月前
|
存储 算法 数据挖掘
python 数学+减治、下一个排列法、DFS回溯法实现:第 k 个排列【LeetCode 题目 60】
python 数学+减治、下一个排列法、DFS回溯法实现:第 k 个排列【LeetCode 题目 60】
|
3月前
|
SQL 算法 数据可视化
leetcode题目69:x的平方根【python】
leetcode题目69:x的平方根【python】
leetcode题目69:x的平方根【python】
|
3月前
|
存储 SQL 算法
leetcode题目70:爬楼梯【python】
leetcode题目70:爬楼梯【python】
|
3月前
|
存储 SQL 算法
leetcode题目68:文本左右对齐【python】
leetcode题目68:文本左右对齐【python】
|
3月前
|
存储 SQL 算法
LeetCode 题目 65:有效数字(Valid Number)【python】
LeetCode 题目 65:有效数字(Valid Number)【python】
|
3月前
|
算法 数据挖掘 开发者
LeetCode题目55:跳跃游戏【python5种算法贪心/回溯/动态规划/优化贪心/索引哈希映射 详解】
LeetCode题目55:跳跃游戏【python5种算法贪心/回溯/动态规划/优化贪心/索引哈希映射 详解】
|
3月前
|
算法 机器人 数据挖掘
LeetCode题目54:螺旋矩阵【python4种算法实现】
LeetCode题目54:螺旋矩阵【python4种算法实现】
|
3月前
|
存储 算法 安全
LeetCode 题目 49:字母异位词分组 5种算法实现与典型应用案例【python】
LeetCode 题目 49:字母异位词分组 5种算法实现与典型应用案例【python】
|
3月前
|
存储 算法 搜索推荐
掌握区间合并:解决实际问题的算法策略和应用案例【python LeetCode题目56】
掌握区间合并:解决实际问题的算法策略和应用案例【python LeetCode题目56】