标签:通用 grep cat user dev shell list .sh 用户
cat a.sh function joke(){ NUM=0 people_list=$(w | sed '1,2d' | awk '{print $1}') for user in $people_list do if [ $user != "root" ] then #echo $user info=$(w | sed '1,2d' | grep "^$user") pts=$(echo $info | awk '{print $2}') while : do echo -e "\033[31mhello $NUM world\033[0m" >/dev/$pts sleep 1 let NUM++ if [ $NUM -gt $1 ] then break fi done & echo "pid is $!" fi done } joke $1sh a.sh 10
效果如下:
[test@centos-6_5 ~]$ hello 0 world
hello 1 world
hello 2 world
hello 3 world
hello 4 world
hello 0 world
hello 1 world
hello 2 world
hello 3 world
hello 4 world
hello 5 world
hello 6 world
hello 7 world
hello 8 world
hello 9 world
hello 10 world
可以加为定时任务
标签:通用 grep cat user dev shell list .sh 用户
原文地址:http://blog.51cto.com/19941018/2067842