i have background download with wget, i want, when the file is greater than 20mb, truncate the first 10mb of file, i have created this script:
if [ $filesize -ge $maxSize ]; then
echo "Truncate.."
kill -STOP $pidDwn
fallocate -c -o 0 -l 10M $fileName
kill -CONT $pidDwn
fi
this snippet recognize file size and truncate it for 10MB from beginning of file.
I stop wget progess, use fallocate for delete first 10MB, and after i resume the wget process for continue the download.
The problem is strange, if the file size is 20mb and i use fallocate WITHOUT resume the process wget, the file remains 10mb, but if i resume the wget process the file return to 20mb instantly and continue to increase with download.
If i use this command after resume the pid
sed -i 1d $fileName
the file remains 10mb but not increase anymore with the download, seems like download is interrupted, but wget process still alive if i use ps aux
for see all process active
any idea for fix it?