shell脚本判断是否存在某文件

情景描述:linux系统正运行着多个world进程,其pid保存在对应.pid文件中。该脚本 遍历对应文件获取pid,kill相应进程。

#!/bin/sh

for i in `seq 1 3`
do
pidfile_="worldd${i}.pid"
if [ -f ${pidfile_} ]; then
pid_=`cat ${pidfile_}`
rm -f ${pidfile_}
echo -n "killing worldd ${i}, pid ${pid_} .."
kill -9 ${pid_}
fi
done

echo "Done."

  

原文地址:https://www.cnblogs.com/wsswlyy/p/7102429.html