bash - Bash 空闲会话时间大于 15 分钟
问题描述
我需要帮助来完成这个。试图让用户会话闲置超过 15 分钟,这些会话没有被启动sshd_config
并杀死它们。这就是我必须拉会话,我如何过滤超过 15 分钟。
#!/bin/bash
IFS=$'\n'
for output in $(w | tr -s " " | cut -d" " -f1,5 | tail -n+3 | awk '{print $2}')
do
echo "$output \> 15:00"
done
解决方案
你可以试试这样的……</p>
for i in $(w --no-header | awk '{print $4}')
do
echo $i | grep days > /dev/null 2>&1
if [ $? == 0 ]
then
echo "greater that 15 mins"
fi
echo $i | grep min> /dev/null 2>&1
if [ $? == 0 ]
then
mins=$(echo $i | sed -e's/mins//g')
if [ $min -gt 15 ]
then
echo "Greater than 15 mins"
fi
fi
done
棘手的部分将是弄清楚pid
要杀死什么。
推荐阅读
- powershell - 简单的 PowerShell 选择字符串模式
- java - Flink - 从数据库属性创建广播流
- vue.js - Vuejs - 获取动态生成的输入字段及其值并在更改时更改其颜色
- javascript - 将服务器上的 div 保存为图像并下载
- jenkins - 詹金斯是否可以在“一排”连续失败中只保留第一次和最后一次失败?
- powershell - 从 PowerShell 中的 Invoke-RestMethod 同时读取和写入同一文件
- java - Java使用正则表达式匹配器获取组
- python - 如何在不滚动的情况下在 jupyter notebook 中绘制所有图
- python - 如何在 python 中使用存储的变量进行发布请求
- reactjs - 当状态变量改变时使用 useQuery