File tree Expand file tree Collapse file tree 1 file changed +19
-10
lines changed Expand file tree Collapse file tree 1 file changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,24 @@ while getopts ":hksi:" opt; do
51
51
esac
52
52
done
53
53
54
+ # Get TTYs with the seconds since the last access time
55
+ TTYS=$(
56
+ who -s \
57
+ | awk ' { print $2 }' \
58
+ | grep -ve " ^:"
59
+ )
60
+ if [ " $TTYS " = " " ]; then
61
+ echo " Suitable TTYs not found; no SSH sessions to find." >&2
62
+ exit 0
63
+ fi
64
+
65
+ TTY_AGES=$(
66
+ echo " $TTYS " \
67
+ | (cd /dev && xargs stat -c ' %U %n %X' ) \
68
+ | awk ' { print $1"\t"$2"\t"' " $( date +%s) " ' -$3 }'
69
+ )
70
+
71
+ # Print header
54
72
if (( KILL == 1 )) ; then
55
73
echo " Killing sshd processes idle more than $MAX_IDLE seconds." >&2
56
74
else
63
81
fi
64
82
echo " " >&2
65
83
66
- # Get TTYs with the seconds since the last access time
67
- TTY_AGES=$(
68
- who -s \
69
- | awk ' { print $2 }' \
70
- | grep -ve " ^:" \
71
- | (cd /dev && xargs stat -c ' %U %n %X' ) \
72
- | awk ' { print $1"\t"$2"\t"' " $( date +%s) " ' -$3 }'
73
- )
74
-
75
- # Get sshd processes of the TTYs; print or kill (-k)
84
+ # Get sshd processes of the TTYs; list or kill (-k)
76
85
while IFS= read -r line ; do
77
86
user=$( echo " $line " | awk ' {print $1}' )
78
87
tty=$( echo " $line " | awk ' {print $2}' )
You can’t perform that action at this time.
0 commit comments