How to find if there are new files in a directory every 2 minutes in shell script?

后端 未结 5 1886
别跟我提以往
别跟我提以往 2021-02-03 14:11

I have a directory called /home/user/local. Every two minutes or so, a new file is dumped into this directory. I need to check this directory every 2 minutes to see

5条回答
  •  没有蜡笔的小新
    2021-02-03 15:01

    Lets say your variable is called $listOF

    Create a script:

    listOfFiles=`ls -t /home/user/local`
    for i in $listOfFiles
    do
    echo "$listOF" | grep $i
    if [[ "$?" -eq "0" ]]
    then
    listOF=$listOF" "$i
    fi
    done
    

    And put this script into the crontab by cmd: crontab -e in format:

    1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * 
    

提交回复
热议问题