编写一个shell脚本(在Bourne shell上运行),它运行一个无限循环来监视拒绝列表上的哪些用户多次登录UNIX系统。
此任务的脚本必须命名为mlog.sh
。以下是脚本的示例输出(如果脚本在最终中断时留下临时文件,则可以)。 $是shell提示符。
$ ./mlog.sh
No user on the user.deny list has multiple logins
No user on the user.deny list has multiple logins
The user John Smith (on the denial list) has logged in more than once!
The user Adam Jones (on the denial list) has logged in more than once!
No user on the user.deny list has multiple logins
No user on the user.deny list has multiple logins
The user David Monks (on the denial list) has logged in more than once!
The user Nick Andrews (on the denial list) has logged in more than once!
请记住,不要使用root帐户权限,作为学生,我们没有root权限,我们可以使用who,users,w,finger来监控登录系统的用户。
w:
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
juanz pts/1 myvpn-35-37.stud 07:34 1:09m 0.20s 0.20s -bash
haydenj2 pts/0 myvpn-p32-107.st 07:23 0.00s 0.90s 0.90s -bash
fhe2 pts/2 xxxxxxxxxxxxxx-e 08:04 6:39 0.14s 0.01s nano menu.sh
chanpw pts/3 myvpn-33-186.stu 07:51 0.00s 0.14s 0.06s joe cp2.sh
fhe2 pts/4 10-200-250-132-e 08:19 35:56 0.08s 0.08s -bash
zijianc pts/5 myvpn-33-162.stu 02:36 6:33m 0.05s 0.05s -bash
zijianc pts/6 myvpn-33-162.stu 02:35 6:32m 0.10s 0.02s nano
我不知道如何使用该表来显示......
期待您的回复!
答案 0 :(得分:0)
if [-f user.deny];然后 手指| awk' {w [$ 2" " $ 3] + = 1} END {for(a in w)if(w [a]> 1)print a}' > user.deny
虽然如此;
做
手指| awk' {w [$ 2" " $ 3] + = 1} END {for(a in w)if(w [a]> 1)print a}' > user.deny |读线时
做
#finger | awk' {w [$ 2" " $ 3] + = 1} END {for(a in w)if(w [a]> 1)print a}' > user.deny
FN = wc -l<user.deny
;
如果[$ FN -eq 0];那么
echo&#34; user.deny列表中没有用户有多个登录&#34 ;;
否则
user.deny列表中的echo&#34; $ line用户有多个登录&#34 ;;
#sleep 3
科幻
完成&lt; user.deny
DONE
其他
echo&#34; no user.deny,退出&#34 ;;
出口;
网络