Need to delete logs with different name from different locations and need to delete the logs more than 5 days.
Ex:
/abc/bcd/fgh/log/log1.txt
/abc/bcd/fgh/test/log2.log
/test/urc/mhg/event.log
/hjy/jghd/qwer/nbcvd/eda.log
Need to delete logs with different name from different locations and need to delete the logs more than 5 days.
Ex:
/abc/bcd/fgh/log/log1.txt
/abc/bcd/fgh/test/log2.log
/test/urc/mhg/event.log
/hjy/jghd/qwer/nbcvd/eda.log
You should take a look at logrotate which is designed to automate this sort of thing for you. You'll make a config file telling it where the logs are and how you want them handled and it will schedule and rotate/remove them for you.
add this script to crontab
#!/bin/bash
LogArray=()
LogArray+=('/abc/bcd/fgh/log/log1.txt')
LogArray+=('/abc/bcd/fgh/test/log2.log')
LogArray+=('/test/urc/mhg/event.log')
LogArray+=('/hjy/jghd/qwer/nbcvd/eda.log')
for (( i=${#LogArray[@]}-1; i>=0; i-- )); do
if test `find ${LogArray[$i]} -ctime +5`
then
truncate -s 0 ${LogArray[$i]}
chmod ""$(stat -c %a ${LogArray[$i]})"" ${LogArray[$i]}
fi
done
exit 0