bash脚本中的条件lsof循环

时间:2015-08-05 14:05:19

标签: macos bash

我找到了一个条件lsof循环的例子,并希望根据我的情况进行调整。

typeset fSrc="/path/to/sourcedir"
typeset fTgt="/path/to/targetdir"

while : ; do
   ls /path/to/sourcedir | while read file ; do
      if [ $(lsof $fSrc/$file | wc -l) -gt 1 ] ; then
           echo "file $file still loading, skipping it"
      else
           mv $fSrc/$file $fTgt/$file
           echo "file $file completed upload, moving it"
      fi
   done
done

我的例子更像是这样:

while any files are present in "/pathto/sourcedir"; do
    if [ lsof "any file" in "/pathto/sourcedir" is being written or modified ]; then
       echo "Files being written or modified, exiting"
       exit
    else
       do something
    fi
done

可以这样做吗?我的逻辑是否接近正确?

0 个答案:

没有答案