9

我在我的 Linux 服务器上使用了一个简单的 Shell 脚本,它检查 rsync 作业是否正在运行,或者是否有任何客户端通过 Samba 从服务器获取一些目录。如果是这种情况,那么什么也不会发生,但是如果没有作业并且没有使用 Samba,那么服务器就会进入休眠状态。

是否有任何简单的命令,可用于检查是否存在与服务器的 ssh 连接?我想将它添加到我的 Shell 脚本中,这样服务器就不会进入休眠状态,如果存在这样的连接的话。

4

2 回答 2

12
于 2013-06-19T18:58:07.233 回答
8

use who command

it gives output like

username  pts/1        2013-06-19 19:51 (ip)

You could parse that to see how many non locals are added and get their usernames (or there are options see man who for more info

gives a count of how many non localhost users there are

who | grep -v localhost | wc -l
于 2013-06-19T18:58:27.167 回答