?

cleanup script

Posted on 2017-12-06
12
Medium Priority
?
91 Views
Last Modified: 2018-01-25
hi,

we have about 3 users say user1, user2, user3 on the weblogic server. The application logs and server logs getting filled up every 3 weeks or so causing server to choke. How to write a script to clean automatically those application log and server log folder contents automatically say every week on friday midngiht at 11 PM

please advise
0
Comment
Question by:gudii9
  • 4
  • 4
  • 4
12 Comments
 
LVL 22

Expert Comment

by:David Favor
ID: 42394393
This is what logrotate does for you.

Just get into your /etc/logrotate.d directory + look through the files there.

Find one which is close to what you require + clone it + rename top lines to match your log files.
0
 
LVL 7

Author Comment

by:gudii9
ID: 42394482
$ /etc/logrotate.d
-bash: /etc/logrotate.d: is a directory


i got message as above.

i do not have tht looks like
any sample script or link or resource for this?
0
 
LVL 22

Expert Comment

by:David Favor
ID: 42394687
You'll have to install logrotate if it isn't installed + refer to your Distro docs to determine where logrotate config files live.

Most mainstream Distros install logrotate by default, to guard /var/log/* files from eating all of disk space.

Likely your system has logrotate installed somewhere.

A simple config file you can likely clone is one I use to rotate WordPress debug logs each night, as poorly coded themes/plugins tends to generate many Gigabytes/day in some cases. The following keeps 10 days of log files...

"/sites/*/logs/*wp-debug.log"
"/sites/*/*/logs/*wp-debug.log"
{
        daily
        missingok
        rotate 10
        compress
        delaycompress
        notifempty
        create 640 www-data www-data
}

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 1

Expert Comment

by:Erik Schminke
ID: 42397323
You tried to execute /etc/logrotate.d ... the message is telling you that is a directory.  You can't do that.

Instead, do an "ls -l" of that directory.  I suspect logrotate actually is installed and you'll see something if you do that.  If log rotate weren't installed, you'd have seen a message to the effect of "No such file or directory" instead of "/etc/logrotate.d is a directory"

Other than that, David is correct.  Logrotate is exactly what you need to periodically clean up steadily growing log files that are no longer relevant.
0
 
LVL 22

Expert Comment

by:David Favor
ID: 42397332
Oops... Erik is correct... /etc/logrotate.d is a directory where all the config files live.

The logrotate program can be run manually + you'll refer to man logrotate for how to run logrotate manually.

Usually you'll use the -dv option to debug a new config file.
0
 
LVL 7

Author Comment

by:gudii9
ID: 42400046
any other alternate solution like simple sample script to this apart from logrotate? please advise
0
 
LVL 1

Expert Comment

by:Erik Schminke
ID: 42400116
Why do you want to kludge something together when logrotate exists to do exactly what you're asking?  And more than that, is well tested, validated, and is accepted as the defacto standard in Linux for performing routine log cleanup?

What exactly do you feel logrotate doesn't provide you that you're attempting to reinvent the wheel for?
1
 
LVL 22

Expert Comment

by:David Favor
ID: 42414837
To answer your question, "any other alternate solution like simple sample script to this apart from logrotate? please advise".

I'd go with Erik's comment.

Why?

You'd basically have to recode logrotate, which has been working... geez... for well over a decade.

Certainly possible, if you have lots of free time.

If you'd prefer to just have something working instantly, use logrotate, which every primary Linux Distro uses to rotate logs.
0
 
LVL 7

Author Comment

by:gudii9
ID: 42417200
any sample script examples?
0
 
LVL 1

Expert Comment

by:Erik Schminke
ID: 42417532
Sample scripts? No. Why? Because it would require custom coding. Why? Because everyone who knows what they're doing would use logrotate, not kludge together their own script.

So I'll ask again: What exactly do you feel logrotate doesn't provide you that you're attempting to reinvent the wheel for?
0
 
LVL 7

Author Comment

by:gudii9
ID: 42417694
You'll have to install logrotate if it isn't installed + refer to your Distro docs to determine where logrotate config files live.

Most mainstream Distros install logrotate by default, to guard /var/log/* files from eating all of disk space.

first of all i am not unix or linux guy but a java person

second my company has separate team to handle all these web logic servers on unix and linux servers.

all we do is create domain directory and use it to deploy applications and clean up logs once in a while.

I am not sure if they can install it for me.

any sample vidoes on how to do this and more about logrotate?
0
 
LVL 1

Expert Comment

by:Erik Schminke
ID: 42431541
As previously noted, based on a previous commented you posted, I believe you already have logrotate installed.  You could execute a command like "which logrotate" to confirm.  On my system, the logrotate command is located at "/usr/sbin/logrotate" as is executable by all users.

[root@localhost ~]# ls -la /usr/sbin/logrotate
-rwxr-xr-x. 1 root root 70248 Aug  1 20:12 /usr/sbin/logrotate
[root@localhost ~]# ls -ld /usr/sbin
dr-xr-xr-x. 2 root root 20480 Jan  8 07:20 /usr/sbin
[root@localhost ~]# ls -ld /usr
drwxr-xr-x. 13 root root 4096 Dec 12  2016 /usr
[root@localhost ~]# 

Open in new window


The command's manpage, which can be read here, notes the command syntax, configuration file format, and provides some select examples.  It allows you to use a custom config and state file location if you don't have root authority on the system.

Logrotate really is the best solution for this type of problem.  Generally speaking, it's primary mode of action, is to rename the logfile, typically to a date based format), compresses it.  As archived log files accumulate past time rules, it will trim the oldest ones.  There is virtually a limitless combination of configuration options to tailor it's behavior to your exact needs; you can even have it fire a custom script somewhere in the process, using, e.g., the prerotate/postrotate directives.
0

Featured Post

SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

Join & Write a Comment

This installment of Make It Better gives Media Temple customers the latest news, plugins, and tutorials to make their Grid shared hosting experience that much smoother.
Can you run Linux on a Windows system?  Yep.  Here's how.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Suggested Courses
Course of the Month6 days, 10 hours left to enroll

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question