找出谁使用python在Linux上登录 [英] Find out who is logged in on linux using python

查看:36
本文介绍了找出谁使用python在Linux上登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要监视8台服务器.所有服务器都安装了龙卷风python服务器.其中一台服务器是一台监视器,它可以轮询其他服务器,并在出现问题时通过SMS提醒我.

I have 8 servers that I would like to monitor. All servers have a tornado python server installed. One of the servers is a monitor that polls other servers and alerts me by SMS if there is a problem.

其中之一是用户登录到其中一台服务器时发出的警报.

One of the alerts is when a user logs into one of the servers.

如何使用Python检测谁在我的Ubuntu服务器上登录?我需要将已登录的用户返回到主监视器.我希望这可以使事情变得清楚.

How can I use Python to detect who is logged in on my Ubuntu server? I need to return logged in users to the main monitor. I hope this makes things clear..

推荐答案

我在网上发现的最好的东西是 psutil .请参见 psutil文档

The best thing I found online is psutil. See the psutil documentation

首先安装psutil:

First install psutil :

pip install psutil

之后,一切变得简单,例如从终端运行python控制台:

After that everything is easy as an example run python console from terminal:

import psutil 

psutil.users()

输出:

[user(name='root', terminal='pts/0', host='your-local-host-from-isp.net',
started=1358152704.0)]

这篇关于找出谁使用python在Linux上登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆