unix编写一脚本程序,精确地查询一个用户

来源:百度知道 编辑:UC知道 时间:2024/06/27 06:43:38
编写一脚本程序,精确地查询一个用户,若这用户不存在,则提示用户不存在,若用户存在则查询并列出该用户的家目录(home),并报告该用户当前在线否

#!/bin/bash
echo "input UserName:"
read n
if(grep -y '$n\:'</etc/password>/home/$n)
then echo "$n's home is:/home/$n"
else
echo "$n is not exist"
rm /home/$n
exit
fi
if(who|grep -y $n>home/$n)
then echo "$n is online"
else echo "$n is not online"
fi
rm /home/$n