首页 > 解决方案 > 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

标签: bash

解决方案


你可以试试这样的……</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要杀死什么。


推荐阅读