注意:用此脚本,icq用户必须先取得系统write命令的授权,具体操作请参见:http://17dvd.cn/unixcd12/article_view.asp?id=1304
#/bin/ksh
#终端聊天shell V050817
#修正改进 V050818
trap 'tput sgr0 rm $HOME/talk.temp $HOME/icq.tmp 2>/dev/null clear exit 0 ' 0 1 3 9 15
trap '' 2
tput bold
clear
icqname="icq"
test -e $HOME/user.dat || { echo "\n 用户配置表 user.dat 不存在\n\n 请联系管理人员解决 ^_^ " read exit 0 }
metty=`tty|awk -F"/" '{print $3}'`
if [ -e $HOME/icq.tmp ]
then
me=`awk '{print $3}' $HOME/icq.tmp`
if [ "$metty" = "$me" ]
then
yourtty=`awk '{print $2}' $HOME/icq.tmp`
yourname=`awk '{ if ($2=="'$yourtty'") print $3}' $HOME/user.dat`
mename=`awk '{if ($2=="'metty'") print $3}' $HOME/user.dat`
mexh=`awk '{if ($2=="'metty'") print $1}' $HOME/user.dat`
clear mesg -y echo "\n 你正与 ${yourname} 聊天\n "
echo "\n ${mename} 正与你聊天,请选择 ${mexh} 与之对聊\n" >/dev/$yourtty
/tcb/bin/asroot write $icqname $yourtty exit 0
fi
fi
while :
do
clear
who | awk '{print $1,$2}' >$HOME/talk.temp
sed '/'"$metty"'/d;/^#/d' $HOME/user.dat |awk 'BEGIN{printf("\n%-5s%-10s%-16s\n"),"序号","TTY","用户名"} \
{printf("%-5s%-10s%-16s\n"),$1,$2,$3}'
echo -n "\n 请输入对方的序号(q键退出程序): "
read xh
test "$xh" = "q" -o "$xh" = "Q" && exit 0
yourtty=`awk '{if ($1=="'$xh'") print $2 }' $HOME/user.dat 2>/dev/null`
test -z "$yourtty" && { echo "\n $xh 未配置TTY\n" read continue }
ut=`awk '{if ($2=="'$yourtty'") print $2}' $HOME/talk.temp 2>/dev/null`
test -z "$ut" && { echo "\n ${ut} 终端未登陆\n" read echo $icqname $metty $yourtty > $HOME/icq.tmp continue }
yn=`awk '{if ($1=="'$icqname'" && $2=="'$ut'") print $1,$2}' $HOME/talk.temp 2>/dev/null`
test -z "$yn" && { echo "\n $icqname 用户未在 $ut 终端上登陆\n" read \
echo $icqname $metty $yourtty > $HOME/icq.tmp continue } || break
done
mesg -y
clear
echo $icqname $metty $yourtty > $HOME/icq.tmp
yourname=`awk '{if ($2=="'$ut'") print $3 }' $HOME/user.dat`
mename=`awk '{if ($2=="'$metty'") print $3 }' $HOME/user.dat`
mexh=`awk '{if ($2=="'$metty'") print $1 }' $HOME/user.dat`
echo "\n 你正与 ${yourname} 聊天\n"
echo "\n 你正与 ${mename} 聊天\n 请选择 ${mexh} 与之对聊\n" >/dev/$yourtty
/tcb/bin/asroot write $icqname $yourtty
user.dat的格式举例:
1 ttyp0 网点1
2 ttyp1 网点2
3 ttyp2 网点3
4 ttyp3 网点4
|
|
|