March 05 2018 Monday
Weather:little rain to cloudy
1、需求:编写一个名为chname的程序,将当前目录下所有的.txt文件更名为.doc文件。
2、需求:编写一个名为chuser的程序,执行中每隔5分钟检查指定的用户是否登录系统,用户名从命令行输入;如果指定的用户已经登录,则显示相关信息。
[root@Dasoncheng sbin]# cat chname.sh
#!/bin/bash
##Changing the name of file likes .txt to .doc!
for i in `find . -maxdepth 1 -name "*.txt" -type f `;
do
i2=`echo $i |awk -F '.txt' '{print $1}'`
mv $i $i2.doc
done
[root@Dasoncheng sbin]# cat o.sh
#!/bin/bash
##2.Test the user who i read whether is online every five miniutes !
read -p "Please input a username !" n
while :
do
if `who |grep -w $n &>/dev/null`;
then
echo "The user $n is online !"
else
echo "Sorry , the user $n is offline !"
fi
sleep 300
done
answer referred
1
#!/bin/bash
find . -type f -name "*.txt" > /tmp/txt.list
for f in `cat /tmp/txt.list`
do
n=`echo $f|sed -r 's/(.*)\.txt/\1/'`
echo "mv $f $n.doc"
done
2
#!/bin/bash
read -p "Please input the username: " user
while :
do
if who | grep -qw $user
then
echo $user login.
else
echo $user not login.
fi
sleep 300
done