with open('/proc/mounts','r') as f:
mounts = [line.split()[1] for line in f.readlines()]
import smtplib
import email.mime.text
msg = email.mime.text.MIMEText('\n'.join(mounts))
msg['Subject'] = <subject>
msg['From'] = <sender>
msg['To'] = <recipient>
s = smtplib.SMTP('localhost') # replace 'localhost' will mail exchange host if necessary
s.sendmail(<sender>, <recipient>, msg.as_string())
s.quit()
4条答案
按热度按时间nfg76nw01#
Python和跨平台的方式:
字符串
然后:
型
zkure5ic2#
在Python中运行
mount
命令并不是解决这个问题的最有效方法。您可以应用Khalid的答案并在纯Python中实现它:字符串
其中
<subject>
、<sender>
和<recipient>
应替换为适当的字符串。3j86kqsm3#
Bash的方式来做,只是为了好玩:
字符串
kognpnkq4#
我不知道有哪个库可以做到这一点,但你可以简单地启动
mount
并返回列表中的所有挂载点,如下所示:字符串
该代码从
mount -v
命令中检索所有文本,将输出拆分为一个行列表,然后解析每行以找到表示挂载点路径的第三个字段。如果你想使用
df
,那么你也可以这样做,但你需要删除包含列名的第一行:型
一旦你有了挂载点(
mntpoints
列表),你就可以使用for in
来处理每个挂载点,代码如下:型
Python有一个名为
smtplib
的邮件处理模块,可以在Python docs中找到信息。