Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to write this script on bash

Write a script that takes all .log files in the dir “/var/log/app” and if
they are older than X days (the number of days will be received as an
argument) tar.gz them with the current date suffix and move them to
“/var/log/app/archive”

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Break it in tasks.
Finding all .logs in a folder not older than a certain time can be done
via find. Check the options maxdepth to stay on one level and mtime for the age.

tar cgf someLog.log.tar.gz --remove-files logfile.log can add it to an archive and delete the file.

mv to move the files. Alternatively you can try to add -C to the tar command, if you feel fancy.

With those commands you should be able to write your script.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading