I am new to unix. I am trying to find the latest log of multiple jobs and delete the latest one.
Can I write a shell script for it? I have tried with basic commands, but there it is selecting a time range and can delete the log, but it may also delete useful logs .
Sharing what I found:
touch -t 201903281325.00 start
touch -t 201903281331.00 stop
find . -newer start \! -newer stop -type f \( -name "**" -o -name "**" \) -exec rm -f {} \;
This deletes all the files in that time limit
What I want to do :
Let the names of jobs are A,B,C, etc, and these run 5 times a day -- say A_1, A_2, A_3, B_1, B_2, B_3, etc.
Say today's run logs generated
Order_created_20190611_1.log
Order_created_20190611_2.log
Order_created_20190611_3.log
Order_zip_rec_20190611_1.log
Order_zip_rec_20190611_2.log
What I have to delete automatically:
Order_created_20190611_3.log
Order_zip_rec_20190611_2.log
I want to automatically find Order_created_20190611_3.log
and Order_zip_rec_20190611_2.log
and delete them.
Example of job names :
Order_created
-- job name20190611
- Date of execution_2
( mentioned at last) - is the number of time it has run._2
means it is running 2nd time for today's run.