Question: I have a simple script which outputs a bunch of logs to screen and I piped the STDOUT to a file to store the logs. Since this script is long running, I needed to rotate the log files so they are chucked into smaller more manageable ones.

The problem I faced was that once the `logrotate` moves the current log file into a new one, the newly created log file is not populated with the logs anymore. It seems that the once the original log file is removed, its file handler is lost and redirection won't work anymore.

I also found [this post](https://serverfault.com/questions/573322/log-rotate-log-from-standard-out) which had the same problem as me and claims that it can be fixed by using `>>` instead of `>` to redirect the output. I tested his solution but it didn't work for me. Does anyone have any idea how to keep the redirection work?

Answer: 
As an alternative, you may also:

* use the logger utility in your script instead of piping, with a dedicated facility (e.g. local5), for example: 

`logger -p local5.info -t myscriptname "this is some log data"`
* configure syslog to write this facility to wanted log file, example (rsyslog.conf) : 

`local5.* /var/log/mylogfile`
* setup logrotate rule for this log.
Another alternative to Iain solution is to use a `postrotate` script to relaunch your script once the rotation has taken place. This is done for lots of daemons (restart or reload the daemon), but not knowing your script I don't know if this solution will suit you or not (does your script depend on some state generated a while ago?).

Contents of `/etc/logrotate.d/your-script-name`:

```
/var/log/your-script-name.log {
    # your current logrotate options
    ...
    postrotate
        # this supposing you have the current pid stored
        cat /run/your-script-name.pid | xargs -r kill
        #relaunch it again
        /usr/local/bin/your-script-name
    endscript
}

```