Linux script that will stop tomcat, archive log files and reboot the server

archivebashcompressionlinuxtomcat

I'm just being lazy here, but does any one have already writen bash script for stopping tomcat service, archive it's log files (zip would be nice) and reboot the server?
(Using logrotate or any other tool)

I want create cron job with following script:

#!/bin/bash
service tomcat stop
# now I don't know what to do with logrotate or something else
init 6

Please help.

Best Answer

You can make a config file for logrotate that takes care of the log rotation. You can place it outside of logrotate.d and then just use it when calling logrotate manually.

Sample:

/path/to/logs/*.log {
        missingok
        rotate 30
        compress
        delaycompress
        notifempty
        create 640 tomcat tomcat
        sharedscripts
}

And then make your script

#!/bin/bash
service tomcat stop
logrotate -f /path/to/your/newly/created/conf/for/logrotate.conf
init 6