【发布时间】:2021-06-21 01:24:30
【问题描述】:
我正在尝试在 Ksh 中编写一个简单的脚本来查看失败的尝试并查看 IP 地址。我正在将 lastb 输出转储到文件中,并且只想获取尝试过的用户名和它来自的 IP 地址。
最后一个输出
user ssh:notty 143.244.175.142 Mon Jun 21 01:04 - 01:04 (00:00)
user ssh:notty 143.244.175.142 Mon Jun 21 00:57 - 00:57 (00:00)
我的脚本是这样的
#!/usr/bin/ksh
FailedLogins="$HOME/sshattempts.txt
if [ -e "$FailedLogins" ]
then
echo "yes file exists"
fi
# while loop
while IFS= read user tty ip
do
printf "$user $ip"
done <"$FailedLogins"
【问题讨论】:
-
您在
FailedLogins="$HOME/sshattempts.txt中缺少"。我将文件命名为ssh_attempts.txt,现在它看起来像ss_hat_tempts.txt。
标签: while-loop ksh