mardi 18 juillet 2017

Solaris few conditions to find file and remove it

I have problem finding solution to my issue, Of course there are many examples on stack etc. however i dont know how to do script that will meet my requrements. I need to find files in folder that are older than 30 days however, before i do such operation i need to check if im looking in proper folder and i need to check if there are any files that meet my requirements.

I tried something like this:

#!/bin/bash
path="path_to_files"
file=`find $path -mtime +30`
if [ -d "$path" ] && [ -d "$file" ]; then
 find $path -mtime +10 exec rm [] \;
 echo "logs older than 30 days have been removed";
else
 echo "logs in $path are up to date";
fi

and its not working, it throws me on screen all files that older than 30 days and return me echo "logs in $path are up to date"...

Thank you in advance for your prompt respond.

Aucun commentaire:

Enregistrer un commentaire