Dear Ladies & Gents,
I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out:
for filename in $(find /var/log/test -type f -mtime +10)
do
read -r firstLine < $filename
echo "$firstLine"
either echo "${firstLine:0:3}" # "${firstLine:0:3}": bad substitution
or echo "${cut -c1-8}" # "${cut -c1-8}": bad substitution
if [ "${firstLine:0:3}" = "MSH" ] || [ "${firstLine:0:3}" = "FHS" ] || [ "${firstLine:0:5}" = "<?xml" ]
then
echo $filename >> /var/log/test/my2.log # Just a log file to keep track of which files got deleted
## rm $filename
fi
done
*****************************************************************
Please assist.
Many thanks in advance, you guys/gals are awesome!