- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Log Rotation Script for Tomcat Logs
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2013 06:27 AM
01-25-2013 06:27 AM
Log Rotation Script for Tomcat Logs
Hi Experts
we are using Apache Tomcat and the Log files are generated in one Log DIR in the below said format.
$ cd SSOlogs
$ ll
total 48
-rw-r--r-- 1 dz900439 unyo 1854 Jan 18 20:15 filecreate.sh
drwxr-xr-x 2 dz900439 unyo 8192 Jan 21 16:25 madhutest
-rw-r--r-- 1 dz900439 unyo 307 Jan 21 16:36 testmove.sh
-rw-r--r-- 1 dz900439 unyo 0 Dec 1 10:10 tomcat.log.Dec1
-rw-r--r-- 1 dz900439 unyo 0 Dec 10 10:10 tomcat.log.Dec10
-rw-r--r-- 1 dz900439 unyo 0 Dec 11 10:10 tomcat.log.Dec11
-rw-r--r-- 1 dz900439 unyo 0 Dec 12 10:10 tomcat.log.Dec12
-rw-r--r-- 1 dz900439 unyo 0 Dec 13 10:10 tomcat.log.Dec13
-rw-r--r-- 1 dz900439 unyo 0 Dec 14 10:10 tomcat.log.Dec14
-rw-r--r-- 1 dz900439 unyo 0 Dec 15 10:10 tomcat.log.Dec15
-rw-r--r-- 1 dz900439 unyo 0 Dec 16 10:10 tomcat.log.Dec16
-rw-r--r-- 1 dz900439 unyo 0 Dec 17 10:10 tomcat.log.Dec17
-rw-r--r-- 1 dz900439 unyo 0 Dec 18 10:10 tomcat.log.Dec18
-rw-r--r-- 1 dz900439 unyo 0 Dec 19 10:10 tomcat.log.Dec19
-rw-r--r-- 1 dz900439 unyo 0 Dec 2 10:10 tomcat.log.Dec2
Maximum number of days for logs to be deleted in one Month
find /home/dz900439/SSOlogs -type f -name "tomcat.*" -mtime +30 -exec cp /tmp/SSOlogs {} \;
echo "waiting for 30 secs"
sleep 10
#find /tmp/SSOlogs -type f -name "tomcat.*" -mtime +30 -exec /usr/contrib/bin/gzip {} \;
find /home/dz900439/SSOlogs -type f -name "tomcat.*" -mtime +30 -exec ls -l {} \; | wc -l
exit
I used the sample above said script
My reqirement was i want to keep 10 days log in the orginal location and move the old logs day by day or once in a week to some other location /tmp and zip the old logs in the /tmp and delete the log file.
Thanks in Advance.
Ajin.S
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2013 01:51 AM
01-26-2013 01:51 AM
Re: Log Rotation Script for Tomcat Logs
>find /home/dz900439/SSOlogs -type f -name "tomcat.*" -mtime +30 -exec cp /tmp/SSOlogs {} \;
You need to swap the order: ... -exec cp {} /tmp/SSOlogs \;
>My requirement was I want to keep 10 days log in the original location and ...
Older than 10 days? Something like this:
TMP=/tmp/SSOlogs
LOGS=/home/dz900439/SSOlogs
mkdir -p $TMP
find $LOGS -type f -name "tomcat.*" -mtime +10 | while read file; do
base=${file##*/}
/usr/contrib/bin/gzip -c $file > $TMP/$base.gz
if [ $? -eq 0 ]; then
# Keep same date
touch -r $file $TMP/$base.gz
rm -f $file
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2013 06:35 PM
01-29-2013 06:35 PM
Re: Log Rotation Script for Tomcat Logs
Hi Dennis
Thanks for your reply .I checked the same script with test environment .Its moving files from orginal location to /tmp and zip the files in /tmp location . I plan to put it into cron for sheduling ,how can i set how frequence in crontab?
0 0 * * * /home/dz991173/logrotate.sh
Ajin.S
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2013 09:30 PM
01-29-2013 09:30 PM
Re: Log Rotation Script for Tomcat Logs
>how can I set how frequently in crontab?
>00 00 * * * /home/dz991173/logrotate.sh
(I recommend always using two digits so it lines up.)
This does it everyday at 0000, midnight:
MM HH DD mm DoW command
If you want it every 12 hours, use a comma to repeat:
00 00,12 * * * command ...
- Tags:
- crontab