cleanup script

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
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
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
gudii9Author Commented:
$ /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
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Erik SchminkeAIX/Linux Systems AdministratorCommented:
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
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
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
gudii9Author Commented:
any other alternate solution like simple sample script to this apart from logrotate? please advise
0
Erik SchminkeAIX/Linux Systems AdministratorCommented:
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
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
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
gudii9Author Commented:
any sample script examples?
0
Erik SchminkeAIX/Linux Systems AdministratorCommented:
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
gudii9Author Commented:
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
Erik SchminkeAIX/Linux Systems AdministratorCommented:
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
gudii9Author Commented:
"which logrotate" to confirm.  On my system, the logrotate command is located at "/usr/sbin/logrotate" as is executable by all users.
when i gave above command it showed same path as yours
/usr/sbin/logrotate
0
gudii9Author Commented:
now how to delete all the log files older than say 1 month
and also all the tmp file older than 1 week
etc.

Please advise
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.