I have a cron job that kicks off a new process every day. The process runs every 5 minutes and appends to a log file.

Another cron job runs every 60 minutes. It takes some of the data in the log file, cleans it up, creates a new log file. This cleaned up log file gets imported into a database. MySQL prevents duplicate entries so the first few lines of each new clean log file gets ignored.

At the end of a day, I'm stuck with 24 cleaned up log files and one raw log file.

If I was to run the clean-up script by first renaming the file to pre-process, do what I need to do, then delete it, would it cause any issues with my first cron script that is logging to the same file every 5 minutes?

My fear is that the original log file is being written to and this other cron task is trying to rename it.

OS: Debian 8

Edit: Interesting. Cron will write to the renamed file.

1 Answer 1


There is no file locking mechanism in place to protect file renaming or deletion because there is no need for it. Renaming or even deleting a file while it is open by another process, even if it actively writes and/or reads data, is harmless.

The processes having the file open would see no difference and will access the original data of the renamed file transparently, and even access a "deleted" file too without noticing the file has been deleted. The actual deletion will only happen when that process exits.

  • Good to know. I need to rethink how to manage my process then. Aug 16, 2015 at 23:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .