LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   crontab (https://www.linuxquestions.org/questions/linux-newbie-8/crontab-679443/)

thecaligarmo 10-27-2008 07:40 PM

crontab
 
Ok, so I have been trying to find any tutorials or anything in order to try and create a script for what I want my crontab to do, but I can't find any. So if anyone can answer my question, or refer me to somewhere that can answer my q that would be AMAZING!! :)

So I'm using Tomcat 5 and I want to have the script so that I can rename the current catalina.out file with the current date (Such as catalina_10_27_2008.out), and then create a new catalina.out file where all of the new logs would go into.

My current script looks something like this:
/sbin/service tomcat5 stop
/sbin/service tomcat5 start


I want to place the whole moving and creating in between the start and stop so that I have a clear indication of when things are happening.

If it helps, the crontab is set so that it updates daily.

Any help would be fantastical!

Thanks :)

estabroo 10-27-2008 07:50 PM

something like this?
Code:

#!/bin/sh
DATE=`date +%m_%d_%Y`
mv /path/to/catalina.out /path/to/catalina_${DATE}.out
/sbin/service tomcat5 stop
/sbin/service tomcat5 start

I would recommend using 2008_10_27 (%Y_%m_%d) instead it'll sort correctly when you ls where 10_27_2008 won't. Also if you can just HUP tomcat5 to have it reopen its log file do that instead of stopping and starting. You can move the file safely to a new name without interrupting tomcat5's access to it if it stays on the same filesystem because tomcat5 has the file open by inode and the inode won't change when you rename it.

thecaligarmo 10-27-2008 07:56 PM

thanks for the recommendation for the date. I'll use it! Also, will this automatically recreate a new catalina.out file then? Cause I didn't notice a specific line that created a new file.

Also, I don't know how to use HUP tomcat5. I'm fairly a newb in this whole realm. How does it work?

Thanks :)

estabroo 10-27-2008 08:13 PM

Sorry, no that didn't create the new file, for that you probably can just do

touch /path/to/catalina.out

And I have no idea if tomcat5 is huppable or not I've never used it (tomcat5 that is).

If you read the manpage for tomcat5 check for SIGHUP and if it supports that signal and reopens its log connections when it gets it then you can kill -HUP <pid_of_tomcat5>

thecaligarmo 10-27-2008 08:44 PM

It doesn't seem like tomcat5 can use HUP. (at least I couldn't find anything on it).

so adding
touch /path/to/catalina.out
would create it and make it so that the output log goes to it rather than the newly moved file?

estabroo 10-27-2008 08:58 PM

Yes as long as you do the stop start stuff.

thecaligarmo 10-27-2008 09:06 PM

Would it matter if I put the script in this order:

stop tomcat
mv catalina
touch catalina
start tomcat


or for touch to work does it have to be:
mv catalina
touch catalina
stop tomcat
start tomcat


?
(sorry for the million questions. Like I said, super newb here)

chrism01 10-28-2008 12:38 AM

See the logrotate service, it's designed to do this for you.
man logrotate


All times are GMT -5. The time now is 02:05 AM.