1. 程式人生 > >惡搞普通用戶終端shell腳本

惡搞普通用戶終端shell腳本

test 任務 gre cat 普通 shel fun world !=

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 $1


sh 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



可以加為定時任務

惡搞普通用戶終端shell腳本