-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathget_memory_left.py
More file actions
38 lines (34 loc) · 1.02 KB
/
get_memory_left.py
File metadata and controls
38 lines (34 loc) · 1.02 KB
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
# Linux command df - report file system disk space usage
# Example:
# pi@raspberrypi ~ $ df -h /
# Filesystem Size Used Avail Use% Mounted on
# /dev/root 30G 6.8G 22G 25% /
#
# This sample run "df -h /" in Python and get the result
import os
def getDfDescription():
df = os.popen("df -h /")
i = 0
while True:
i = i + 1
line = df.readline()
if i==1:
return(line.split()[0:6])
def getDf():
df = os.popen("df -h /")
i = 0
while True:
i = i + 1
line = df.readline()
if i==2:
return(line.split()[0:6])
# Disk information
description = getDfDescription()
disk_root = getDf()
print(disk_root)
print(description[0] + " : " + disk_root[0])
print(description[1] + " : " + disk_root[1])
print(description[2] + " : " + disk_root[2])
print(description[3] + " : " + disk_root[3])
print(description[4] + " : " + disk_root[4])
print(description[5] + " : " + disk_root[5])