It is typical that we need to schedule (cron) operations on files for archiving or pre/post – processing purpose. Below script is and example, can be use to simplify with customization of your example:
#!/bin/bash
source_dir="11"
dest_dir="22"
log_file="log.txt"
now=$(date +%s)
echo "$now START Files to move from $source_dir to $dest_dir" >> $log_file
files_to_move=$(find $source_dir -type f)
echo $files_to_move >> $log_file
xargs -I{} -n 1 mv {} "$dest_dir" <<< $files_to_move
echo "$now END move file" >> $log_file
echo "$now START Remove files older than 30 days" >> $log_file
remove_files=$(find $dest_dir -type f -mtime +30)
echo $remove_files >> $log_file
xargs -I{} rm {} <<< "$remove_files"
echo "$now END -- Remove files" >> $log_file
No Comments