| 您的位置:首页 > 文档 > Shell > |
文章分类热门文章 |
finger统计同ip地址的tty终端数创建:2005-10-26 00:49:43 作者:Unlinux 来自: http://www.Unlinux.com finger fz99 Login name: fz99 In real life: fz99 Directory: /usr/users/fz99 Shell: /bin/ksh On since Sep 23 15:44:05 19 minutes Idle Time on ttyp1 from 134.236.9.169 On since Sep 23 16:27:26 3 minutes 9 seconds Idle Time on ttyp2 from 134.236.118.134 On since Sep 23 16:04:27 7 minutes 39 seconds Idle Time on ttyp3 from 134.236.9.169 On since Sep 20 23:51:21 7 minutes 39 seconds Idle Time on ttyp4 from 134.236.114.132 On since Sep 23 07:56:33 on ttyp5 from 134.236.117.131 On since Sep 23 08:05:25 4 minutes 39 seconds Idle Time on ttyp7 from 134.236.113.131 On since Sep 23 14:30:17 2 hours 3 minutes Idle Time on ttyp9 from 134.236.120.133 # finger -f fz99|awk '{ printf $NF }' fz99/bin/kshTime134.236.9.169Time134.236.118.134Time134.236.9.169Time134.236.114.132Time134.236.117.131Time134.236.113.131Time134 # 要统计同ip地址的tty终端数,终端数大于3,送消息给大于3的各个终端,如何写? 程序好像倒不难写,不过还是觉得亲眼看一看,然后打个电话就通知一下就可以了 100来个终端,电话也不固定。山地獾,简单,就请下笔吧。 ## 当同一地址的终端数小于或等于cnt4ip时,不理会 #cnt4ip=3 cnt4ip=0 #测试时取值 finger -f | awk '{printf("%s|/dev/tty%s ",substr($0,60,15),substr($0,32,2)) }' | sed 's/^|/127.0.0.1|/g' |sort >fl1 cut -d "|" -f1 fl1 |sort -u > fl2 for ip in `cat fl2` do grep $ip fl1 >fl3 lines=`wc -l fl3 |awk '{print $1}'` if [ $lines -le $cnt4ip ] then continue fi for str in `cat fl3` do str4ip=`echo $str | awk -F "|" '{print $1}'` str4tty=`echo $str | awk -F "|" '{print $2}'` echo " 快点退出! 不然我扣你的钱! " > $str4tty done done > echo " 快点退出! 不然我扣你的钱! " > $str4tty 俺就喜欢这句,建议改为: echo " 快点退出! 不然枪毙 " > $str4tty 这样子倒不如把这一脚本修改一下,放到/etc/profile中去或者在当中调用一下,他们的$HOME/.profile必须读一下/etc/profile,$HOME/.profile性质改为只读。当统计发现已经3个终端了,就不让继续login就好了。扣他们的钱一说,也可以放进login message中去嘛,呵呵。 怎么修改才能实现红袖添香说的功能呀? 可以把那段代码写在一个SHELL 里。然后在.profile 文件中调用一下。 既然又有人up了,就简单再说一下。 以前在BSD版里也有人问到这样类似的问题,能否限制用户的登录次数。当时我是这么回答的,理论上可以实现,但实际中可能要考虑挺多东西,要根据自己的情况作调整。 强制用户login前必须执行下面这一段脚本,可以是/etc/profile或另外一个单独脚本或其它形式,在$HOME/.profile中调用它,并且规定只读属性,总之要保证,必须让它被执行过。还要考虑到,如果用户使用其它shell, 或根本就是为了逃避$HOME/.profile的限制而故意chsh后使用其它shell的情况等等。 。。。 LOGINS=`who | grep $USER | wc -l` if [ "$LOGINS" -ge 3 ]; then echo "$USER: too many login sessions, sorry!" exit fi 下面引用由laoxia在 2002/12/20 01:39am 发表的内容: > echo " 快点退出! 不然我扣你的钱! " > $str4tty 俺就喜欢这句,建议改为: echo " 快点退出! 不然枪毙 " > $str4tty 俺想改为 echo " 退出! 然后将罚款交至帐号XXXX " > $str4tty XXXX是的帐户 我在solaris 5.6上测试, 好像要这样写: finger -f | awk '{printf("%s|/dev/%s ",substr($0,60,15),substr($0,32,6))}' 转载自:http://www.unlinux.com/doc/shell/20051026/107.html 【评论】 【加入收藏夹】 【大 中 小】 【打印】 【关闭】 ※ 相关链接 无相关信息 |