0

In my workplace, I've inherited the responsibility of managing a web server. It's a CentOS Linux virtual machine, running on Amazon AWS EC2. Alongside serving web pages, there is a pile of scheduled tasks, background processing and database operations that happen.

Just now I was manually running a Bash script that calls Oracle SQL*Plus, which reads a SQL script with a load of UPDATE statements and calls to refresh materialized views. Maybe none of that is relevant, but I wanted to give some context.

The Bash script writes output to a log file in /tmp, and I was using the command tail -f output.log to monitor the output. It was running for a long time - maybe 20 minutes - with output slowly appearing in my terminal, but then I got a message: tail: output.log: file truncated and the Bash script stopped running. The log file exists in /tmp but it has size 0. I was hoping to go through the log file in detail to see what DB errors were reported, so I could fix things.

My question is, what could cause this file truncation to happen? I don't think the file itself was very big - only something like 200 lines. This is all kind of new to me, and I don't really know where to start, or what to suspect as potentially problematic.

4
  • Did someone else run the same bash script, and does it overwrite the log?
    – Jeff Schaller
    Commented Dec 9, 2019 at 15:33
  • @JeffSchaller, no, this is not possible. This is a script run only manually, maybe once a month, and I'm the only one currently accessing this server.
    – osullic
    Commented Dec 9, 2019 at 15:34
  • Is it a CentOS7 system with systemd and its related /tmp cleaner?
    – Jeff Schaller
    Commented Dec 9, 2019 at 15:38
  • @JeffSchaller cat /etc/os-release tells me CentOS Linux version 7 (Core). If I run du in /tmp it says that 17MB is used. If I run df -Ph . it says that 10GB is used and 10GB is available. I don't know about systemd or its /tmp cleaner, but there are files in /tmp with timestamps of more than a week ago.
    – osullic
    Commented Dec 9, 2019 at 15:52

1 Answer 1

1

Although unlikely to be configured to operate in /tmp, the tool logrotate could truncate a file when performing its rotation.

Also if a process writes to the file without an append flag, this would also cause it to truncate the file. In bash this is the difference between a single '>' and double '>>'. In other languages it's the 'a' mode instead of 'w' mode. This depends entirely on what process was writing to the log.

1
  • Thank you, it was an obvious answer - the bash script has multiple calls to sqlplus, each writing output to the same log file, but the bash script uses single '>' instead of double.
    – osullic
    Commented Dec 9, 2019 at 15:55

You must log in to answer this question.

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