I have cronjob to run a script every day in specific time. The script is for conversion a large file (about 2GB) in specific folder. The problem is that not every day my coleague put the file in the folder before the time, written as cronjob.
Please help me to add commands in the script or to write second script for:
- Check if the file exists in the folder.
- If the previous action is true, check the file size every minute. (I would like to avoid conversion of still incomming large file).
- If filesize stays unchanged for 2 minutes, start the script for conversion.
I give you the important lines of the script so far:
cd /path-to-folder
for $i in *.mpg; do avconv -i "$i" "out-$i.mp4" ; done
10x for the help!
NEW CODE AFTER COMMENTS:
There is file in the folder!
#! /bin/bash
cdate=$(date +%Y%m%d)
dump="/path/folder1"
base=$(ls "$dump")
if [ -n "$file"]
then
file="$dump/$base"
size=$(stat -c '%s' "$file")
count=0
while sleep 10
do
size0=$(stat -c '%s' "$file")
if [ $size=$size0 ]
then $((count++))
count=0
fi
if [ $count = 2 ]
then break
fi
done
# file has been stable for two minutes. Start conversion.
CONVERSION CODE
fi
MESSAGE IN TERMINAL: Maybe error???
script.sh: 17: script.sh: arithmetic expression: expecting primary: "count++"
Well, I finally made some working code as follows:
Is the next line the right one to loop the same script???
The right code after comments below is