LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-27-2008, 07:40 PM   #1
thecaligarmo
LQ Newbie
 
Registered: Oct 2008
Posts: 7

Rep: Reputation: 0
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
 
Old 10-27-2008, 07:50 PM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
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.
 
Old 10-27-2008, 07:56 PM   #3
thecaligarmo
LQ Newbie
 
Registered: Oct 2008
Posts: 7

Original Poster
Rep: Reputation: 0
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
 
Old 10-27-2008, 08:13 PM   #4
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
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>

Last edited by estabroo; 10-27-2008 at 08:15 PM. Reason: clarify hup
 
Old 10-27-2008, 08:44 PM   #5
thecaligarmo
LQ Newbie
 
Registered: Oct 2008
Posts: 7

Original Poster
Rep: Reputation: 0
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?
 
Old 10-27-2008, 08:58 PM   #6
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
Yes as long as you do the stop start stuff.
 
Old 10-27-2008, 09:06 PM   #7
thecaligarmo
LQ Newbie
 
Registered: Oct 2008
Posts: 7

Original Poster
Rep: Reputation: 0
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)
 
Old 10-28-2008, 12:38 AM   #8
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

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


Reply

Tags
cronjob, crontab, log, script, tomcat


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
replaced crontab, now should get crontab back to what it was raminn Linux - Newbie 2 10-20-2008 07:15 PM
man crontab(5) vs crontab(1) Canis Polaris Linux - Newbie 2 06-04-2008 04:03 PM
crontab tommytomato Ubuntu 4 07-03-2007 03:15 PM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM
Crontab WiWa Linux - Software 1 10-06-2003 05:20 PM


All times are GMT -5. The time now is 05:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration