vaj oja
vaj oja

Reputation: 1161

sh script to rotate logs periodically

I would like to create a sh script which can run the following command via cron periodically

00 01 * * * /usr/local/sbin/rotatenginxlogs.sh > dev/null 2>&1

how should i write the sh script?

Upvotes: 0

Views: 774

Answers (1)

Anshul Goyal
Anshul Goyal

Reputation: 76837

Instead of using a cron job to rotate nginx logs, you should investigate using logrotate utility to do the same.

From the man page:

Logrotate allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.

That way, you won't need to use cron jobs. Check /etc/logrotate.d, there in the nginx file, you will have to setup configuration. Check this tutorial on setting up the same

Upvotes: 1

Related Questions