I have some old file in my Linux server and I need to remove those files which are older than 5 days based on the threshold value.
log_space_checker() {
Use=$(df -kh /logs | awk 'END{gsub("%",""); print $4}');
DATAUSE=$(df -kh /logs | awk 'END{gsub("%",""); print $4}');
}
remove_files(){
RemoveFiles="/logs/abc/abc.log.*"
find "$RemoveFiles" -mtime +1 -type f -delete
}
disk_space_monitor() {
log_space_checker;
if [[ $DATAUSE -gt $TH ]] ; then
remove_files;
fi
}
TH=7
disk_space_monitor
Is the script correct?
-deleteto-printand review its behaviour. create files with old timestamps usingtouchif needed too. – steve Jul 26 '16 at 06:29Usevariable here ? – Rahul Jul 26 '16 at 06:36"/logs/abc/abc.log.*"(with star at the end of the name)? – Jasen Jul 26 '16 at 08:18df -khwould ask for output both in kB and in "human readable" (variable units). Also the fourth column (counting from 1) of GNU coreutilsdfoutput is the available space, not the percentage. – ilkkachu Jul 26 '16 at 08:41remove_files()you haveRemoveFiles="/logs/abc/abc.log.*". To expand that with a shell glob (so that the*matches as a wildcard rather than a literal asterisk) you must not quote it, sofind $Remotefiles ...– Chris Davies Jul 26 '16 at 09:03