01-28-2021, 09:25 AM
Here's the Script of deleting the older files and create a backup before delete the file on a remote server..
##First create a file :
touch ~/delete-old.sh
##Then open the file using any editor
vim ~/delete-old.sh
#!/bin/sh
# A table that contains the path of directories to clean
rep_log=("/root/m")
echo "Cleaning logs - $(date)."
#loop for each path provided by rep_log
for element in "${rep_log[@]}"
do
#display the directory
echo "$element";
nb_log=$(find "$element" -type f -mtime +10 | wc -l)
if [[ $nb_log != 0 ]]
then
rsync -arvz -e 'ssh -p 22' "$element" root@192.168.1.1:/remote-path
find "$element" -type f -mtime +10 -delete
echo "Successfull!"
else
echo "No log to clean !"
fi
done
##Then Save it
##First create a file :
touch ~/delete-old.sh
##Then open the file using any editor
vim ~/delete-old.sh
#!/bin/sh
# A table that contains the path of directories to clean
rep_log=("/root/m")
echo "Cleaning logs - $(date)."
#loop for each path provided by rep_log
for element in "${rep_log[@]}"
do
#display the directory
echo "$element";
nb_log=$(find "$element" -type f -mtime +10 | wc -l)
if [[ $nb_log != 0 ]]
then
rsync -arvz -e 'ssh -p 22' "$element" root@192.168.1.1:/remote-path
find "$element" -type f -mtime +10 -delete
echo "Successfull!"
else
echo "No log to clean !"
fi
done
##Then Save it