if [ -n "$line" ]; then //判断字符串是否为空,一定要有双引号
if [ "$PIDS" != "" ]; then//判断字符串是否为空,一定要有双引号
if [ -f $file ]; then // 判断是否是目录
newfile="${file//查询的字符串/替换的字符串}” //字符串替换
if [[ -f $sourceFile ]] && [[ ${sourceFile##*.} == "mp4" ]] ; then //判断扩展名
#判断是否需要重启ffmpeg进程
path=/home/media/fileloop/restart.txt
backup=/home/media/fileloop/p_txt_backup
for line in $(cat $path | sed -e 's/\r//g')
do
if [ -n "$line" ]; then
echo $(date -d "today" +"%Y%m%d_%H%M")_$line
echo "ps axu | grep ffmpeg | grep \"/data/media/fileloop/$line/p.txt\" | grep -v grep | awk '{print \$2}'"
pid=`ps axu | grep ffmpeg | grep "/data/media/fileloop/$line/p.txt" | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]; then
echo "kill -9 $pid"
kill -9 $pid
cp /home/media/fileloop/$line/p.txt $backup/${line}_$(date -d "today" +"%Y%m%d_%H%M%S").txt
else
echo "can not grep \"/data/media/fileloop/$line/p.txt\" in processlist"
fi
fi
done
#cp $path /root/osstools/restart_backup/
cp /dev/null $path
标签:shell,grep,media,代码,pid,判断,line,txt,fileloop
From: https://www.cnblogs.com/netstat/p/18075713