shell脚本编写

来源:百度知道 编辑:UC知道 时间:2024/05/21 07:18:35
编写一个Shelll脚本,显示当天日期,查找给定的某用户是否在系统中工作。如果在系统中,就发一个问候给他。

脚本1.sh内容如下:
执行方式: sh 1.sh username

date
user=`who -u|awk '{print $1}'|grep $1` #猔:硂ńΤㄢ?"はま腹"
flag=0
echo $user |while read line
do
if [ $line = $1 ]
then
flag=1
fi
echo $flag
done
echo $flag
if [ $flag -eq 1 ]
then
write $1 < 1.txt #1.txt?只癳ず甧
else
echo "user $1 is not online"
fi
~
~

echo $(who) | grep "root" && echo "hello" | write root

不知道是不是这个意思