Shell script for moving file with delay
Q. Create a script to move all the files with extension .json which have been modified in the last 2 days from the directory /opt/json to the directory /usr/json-backup at a rate of 100 files per minute. Rate of 100 file means that it should move only 100 files at a time, pause for 1 minute and transfer 100 files again till all the files have been moved. After it has successfully moved all the files to the /usr/json-backup create a compress backup of the directory along with the date(ddmmyyyy format) in the name of the compressed file
Solution:
#!/bin/bash
datetime_var="$(date +"%d-%m-%y")"
echo "$datetime_var"
cnt=0
for i in $(find /opt/json -name '*.json'-mtime -2);do
mv $i /opt/json-backup
cnt=$((cnt+1))
if [ $((cnt % 100)) -eq '0' ]; then
sleep 60
fi
done
tar -czvf /backuppath/json-backup_$datetime_var.tar.gz /opt/json-backup