监控linux环境是是否出现过指定进程

#!/bin/bash
output_file="/home/yan/logfile.txt"
while true
do
ps aux | grep "[t]ar" >> "$output_file"
if [ $? -eq 0 ]; then
echo "" >> "$output_file"
# 等待1秒再进行下一次检测
fi
sleep 1
done

posted @ 2024-08-21 09:24  小白成长记-yan  阅读(9)  评论(0)    收藏  举报