#!/usr/bin/sh
while [ 1 ]
do
ps_types="`who -R|grep -v '10.71.175.39'|grep -v grep|awk '{print $2}'`"
#echo ${ps_types}
for ps_t in "${ps_types}"
do
ps -u $LOGNAME|grep csh|grep -v grep|awk -v ps_t="${ps_t}" 'BEGIN{split(ps_t,psarray," ")}{ for (i in psarray) {if ($2==psarray[i]) printf "kill_pid.sh %s
\n",$1}}'|sh
done
who -R|grep $LOGNAME|grep -v grep
sleep 10
done
while [ 1 ]
do
ps_types="`who -R|grep -v '10.71.175.39'|grep -v grep|awk '{print $2}'`"
#echo ${ps_types}
for ps_t in "${ps_types}"
do
ps -u $LOGNAME|grep csh|grep -v grep|awk -v ps_t="${ps_t}" 'BEGIN{split(ps_t,psarray," ")}{ for (i in psarray) {if ($2==psarray[i]) printf "kill_pid.sh %s
\n",$1}}'|sh
done
who -R|grep $LOGNAME|grep -v grep
sleep 10
done
本文介绍了一个使用Shell脚本实现的自动化任务案例。该脚本通过循环不断地获取当前登录用户信息,并针对特定条件执行进程查找及杀掉指定进程的操作。此外,脚本还包含了定时睡眠机制来控制任务执行频率。

被折叠的 条评论
为什么被折叠?



