Informing the IBM Community

Logrotate on IBM i


In this article I will talk about an open-source utility that hasn’t got much airspace since it was released on our IBM i.

Its called logrotate, a handly utility that can help us manage the many logs we have on our IFS. 

As we all know, log files can easily get out of hand. 

How many times have our clients call us up and moaned about performance, upon investigation it becomes apparent the php.log file has never been cleared down and holds millions of records.

Logrotate is here to help you get around this problem and clean up the logs on a periodic basis.

Logrotate is very powerful. It allows automatic rotation, compression, removal and mailing of log files.
Each log file may be handled daily, weekly, monthly, or when it grows too large. All very useful.

Installing logrotate

If you are confident using a Bash session connected to your IBM i using SSH and a quick Yum install will get you going.

yum install logrotate

Or, use Open Source Package Management from Access for Client Solutions (ACS), which can be seen in the figure below.


Do you have the excellent man utility on your box, if not, why not!

See my previous PowerWire article Where’s that manual gone?

Using man, we can see the manual for logrotate.

Man logrotate

Please be aware that the logrotate utility resides in the /QopenSys/pkgs/sbin folder, so adjust your profile path, or prefix it with this folder if you intend using this feature.  For example



Logrotate works off very simple text configuration files.  Create this file, in any IFS folder, using your favourite editor, VS Code for example.

In this example, I’ll create a configuration file that checks and maintains all the logfiles in my /PowerWire/Logs folder on my IBM i IFS. I’ll create a file called powerwire.conf in my /powerwire/logrotate folder, with the following entries.

This is not an extensive list by any means.  Check out the logrotate command using MAN in my top-tip above.

Running Logrotate

Now we have our config file, let me test it out.

All we must do, is to run logrotate with our configuration file as the first parameter, as in

logrotate /powerwire/logrotate/powerwire.conf

If we only want to check our configuration file is holding all the necessary details, we can run logrotate in debug mode, which will perform just a dry run and not actually perform any archiving.

To run in debug mode, just use the -d flag after logrotate.  This can be seen in the figure below.

Here we can see each log file is being interrogated to check if any archiving needs to be performed.

Once you are happy with the archiving, just run the logrotate command without the -d flag and away it goes, sorting out your logs.  All very neat!


If we want to perform logrotate on a scheduled basis we can easily add it to our job scheduler using the command seen below.

ADDJOBSCDE JOB(TIDY_LOGS)                                    

           CMD(QSH CMD(‘/QOpenSys/pkgs/sbin/logrotate /powerwire/logrotate/powerwire.conf’))





           TEXT(‘Tidy log files’)                             


Another great addition to the open source on IBM i catalogue, that opens the possibilities of what can be achieved on the IBM i server.

All the examples I have written for this article can be found on my open-source repository on GitHub, which can be found at

If you have any questions, either on this article, or anything else on the IBM i, use the comments below, or send me a message on twitter @AndyYouens

Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems with over 40 years IBM midrange experience. 

IBM Champion 2021

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.


2 responses to “Logrotate on IBM i”

  1. Leonardo Villalobos avatar
    Leonardo Villalobos

    Hello Andy
    First of all thanks for this valuable article, I am trying to carry out the configuration, however when testing, it shows me the following message:
    error: /logrotate/logapache.conf:1 lines must begin with a keyword or a filename (possibly in double quotes)
    Could you please help me?

Leave a Reply

Your email address will not be published. Required fields are marked *