shell编程 给定用户是否登陆

来源:百度知道 编辑:UC知道 时间:2024/06/05 07:44:47
查找用户给定用户是否登陆,是则输出"*** logged in ", 否,则输出"*** is not here"

#!/bin/sh
if [ $# != 1 ];then
echo usage: zd007 login
exit -1
fi
tmpstr=`w -h $1|awk '{print $1}'`
if [ "$tmpstr" != "" ]; then
echo $1 logged in
else
echo $1 is not here
fi
exit 0

在ubuntu 6.06下调试通过