gpt4 book ai didi

bash - 无法跳出最里面的 while 循环——Bash - Ubuntu

转载 作者:行者123 更新时间:2023-12-04 23:29:07 25 4
gpt4 key购买 nike

每当两个 MD5 校验和($SUMCHK1 和 $SUMCHK2)在此脚本中匹配时,我就会卡在最里面的 while 循环中,因此脚本永远不会结束。当两个日志文件匹配时,我在屏幕上得到两个 md5sum 的无尽 echo 。

#!/bin/bash

FULLPATH=$1
FPS=$2
AVI=$(basename $1)
AVIDIR=$HOME/q7video/$AVI
TMPFILE=$AVIDIR/tmp.txt
TMPFILE2=$AVIDIR/tmp2.txt
NEWFILES=$AVIDIR/tmp3.txt
FFLOG=$AVIDIR/ffmpeg.log
LOGFILE=$AVIDIR/log.log
FACESDIR=$AVIDIR/faces

# CREATE FOLDER STRUCTURE, NO ERROR IF DIR PRE-EXISTS
mkdir --parents $AVIDIR
mkdir --parents $FACESDIR
touch $TMPFILE $TMPFILE2 $NEWFILES $LOGFILE
echo $AVI > $LOGFILE

# DUMP THUMBNAILS FROM SPECIFIED AVI FILE
ffmpeg -i $FULLPATH -f image2 -vf fps=fps=$FPS $AVIDIR/$AVI%03d.jpg </dev/null >/dev/null 2>$FFLOG &

# DELAY TO ALLOW LOOP A WORKING DIRECTORY BEFORE START
sleep 2

#TOUCH FILES TO PREVENT NO FILE ERROR
touch $TMPFILE $TMPFILE2

# INITIALIZE VARIABLE FOR LOOP
CHECK=`pgrep ffmpeg`
I=0
SUMCHK1=`md5sum $TMPFILE`
SUMCHK2=`md5sum $TMPFILE2`

while [[ "$CHECK" -gt "$I" ]]; do
sleep 2
echo FFMPEG RUNNING
ls $AVIDIR/*.jpg > $TMPFILE
while [[ "$SUMCHK1" != "$SUMCHK2" ]]; do
comm -23 $TMPFILE $TMPFILE2 > $NEWFILES
while read F ; do
echo $F
echo $F >> $TMPFILE2
echo $F >> $LOGFILE
python opencvtest.py $F >> $LOGFILE
done < $NEWFILES
ls $AVIDIR/*.jpg > $TMPFILE
SUMCHK1=`md5sum $TMPFILE`
SUMCHK2=`md5sum $TMPFILE2`
echo $SUMCHK1
echo $SUMCHK2
done
CHECK=`pgrep ffmpeg`
echo $CHECK
done



# COPY IMAGES WITH A FACE TO FACESDIR


# CLEANUP LOGS
#rm $TMPFILE $TMPFILE2 $NEWFILES

最佳答案

这可以在不需要校验和的情况下完成。

# INITIALIZE VARIABLE FOR LOOP
CHECK=`pgrep ffmpeg`
I=0

while [[ "$CHECK" -gt "$I" ]]; do
sleep 2
echo FFMPEG RUNNING

# get the current file list
ls -1 $AVIDIR/*.jpg | sort > $TMPFILE

# compare current file list with previous list and extract new file list
comm -23 $TMPFILE $TMPFILE2 > $NEWFILES

# process new files
while read F ; do
echo $F
echo $F >> $LOGFILE
python opencvtest.py $F >> $LOGFILE
done < $NEWFILES

# save the current file list to be used as previous list in next run
cp $TMPFILE $TMPFILE2

CHECK=`pgrep ffmpeg`
echo $CHECK
done

顺便说一句,循环体应该在 ffmpeg 之后再次执行。已完成以确保最后一组图像不会从处理中跳过。

关于bash - 无法跳出最里面的 while 循环——Bash - Ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26959589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com