Script For Deleting Contents of "Live" Log File


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script For Deleting Contents of "Live" Log File
# 1  
Old 08-24-2010
Script For Deleting Contents of "Live" Log File

In our shop, we have a situation where a log file from our interface engine software has begun maxing out in file size (reaching the 32-bit "2147483647" limit). Currently, the only way to rectify this is to stop the interface and restart it, which generates a new log. Easy enough, but the interface is for a medical facility - so intermittent stops/starts is highly discouraged. I've tried deleting contents of the file (after first backing it up) with various commands. Although I get what APPEARS to be an emptied file, it shows the same file size when moved back into the directory where it's written to. When viewing the log, there IS blank space up to the "new" log entries - but the file size remains the same - thus, defeating my intent. Is there any way to clear the log file, and revert it back to zero-size, without having to shut down this interface? I cannot create a new file; it is appended with a PID, which has to remain the same. Thanks for any help.
# 2  
Old 08-24-2010
Which commands did you try to use to empty this file?
# 3  
Old 08-24-2010
Try renaming the logs then sending SIGHUP to whatever daemon is writing to these files. If the daemon is well-behaved, SIGHUP should cause it to reopen its logfiles without restarting(you should see new files created), after which you can safely delete the old, renamed logfiles.
# 4  
Old 08-24-2010
Quote:
Originally Posted by bartus11
Which commands did you try to use to empty this file?
I used the "cat /dev/null > filename", and also tryed vi'ing the file and deleting contents with ":g/.*/d". Both seemed to work, inasmuch as deleting the contents; just won't get it back to a zero-size file (in the log's "live" environment). Thanks
# 5  
Old 08-25-2010
Quote:
Originally Posted by rjhjr64
I used the "cat /dev/null > filename", and also tryed vi'ing the file and deleting contents with ":g/.*/d". Both seemed to work, inasmuch as deleting the contents; just won't get it back to a zero-size file (in the log's "live" environment). Thanks
Corona688 is right here. You will need to force the process to close and reopen the file.

When you redirect output onto the existing file (>logfile or cat /dev/null >logfile) you are causing the file to be unlinked from the filesystem, but if any processes still have an open file descriptor to the file, the disk space is not released and the process will continue to see the file that it has been using all along. This is why you see an empty file in the file system (reported by ls) but the space is still used (reported by du/df) and the application still has issues.
# 6  
Old 08-25-2010
As others have posted, if the process is well-behaved, you should be able to rename the file then send it a SIGHUP and it should start using a new file. You might have to create the new log file using something like "touch" first, though.

If that doesn't work, the application is broken. Assuming you have an uptime requirement, the failure of the application to properly handle log files is causing it to fail to meet its uptime requirement. Make the developer fix it.

Because it's broke.

Just because the developer didn't THINK about the impact of of failing to manage log files doesn't mean it's OK to fail like that.
# 7  
Old 08-25-2010
As mentionned above, moving your file will not solve your issue, another alternative if it works in your case would be to copy (not move!) the file elsewhere, then blanking the log file:
Code:
>logfile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

replace the contents of first column of file "X" with second Column of file "X" in file "Y"

Hi! I am having 02 files. In first file" X" I am having 02 Columns TCP-5100 Sybase_5100 TCP-5600 Sybase_5600 Second file "Y" for example-- :services ( :AdminInfo ( :chkpf_uid ("{A2F79713-B67D-4409-83A4-A90804E983E9}") :ClassName (rule_services) ) :compound ()... (12 Replies)
Discussion started by: shahid1632
12 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

How to find a file which are not ends with ".zip" and which are ends with "*.log*" or "*.out*"?

I am new to bash/shell scripting. I want to find all the files in directory and subdirectories, which are not ends with “.zip” and which are contains in the file name “*.log*” or “*.out*”. I know below command to get the files which ends with “.log”; but I need which are not ends with this... (4 Replies)
Discussion started by: Mallikgm
4 Replies

5. Shell Programming and Scripting

Deleting "user input line number" from a file using sed

Hi I want to delete a line from a txt file for which the line number is user input. Say when user selects 19, the 19th line would be deleted from the file. Can anyone please provide me with a sed one liner for the same... I tried sed -i. The interaction would be like this Enter the line... (4 Replies)
Discussion started by: sudeep.id
4 Replies

6. UNIX for Dummies Questions & Answers

Deleting "user input line number" from a file using sed

Hi I want to delete a line from a txt file for which the line number is user input. Say when user selects 19, the 19th line would be deleted from the file. Can anyone please provide me with a sed one liner for the same... I tried sed -i. The interaction would be like this Enter the line to... (1 Reply)
Discussion started by: sudeep.id
1 Replies

7. Shell Programming and Scripting

perl's substitution operator "s" with file contents?

Please show me how to make substitution over the contents of a file in a perl script. In a perl script, the core part of substitution operation is s/FINDPATTERN/REPLACEPATTERN/g; However, I cannot figure out how to make the substitution occur over the contents of a file. The following... (3 Replies)
Discussion started by: LessNux
3 Replies

8. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

9. Shell Programming and Scripting

ksh script that echo " please insert your name " and store the output to a login.log file.

Hello All Nice to meet you all here in this forum, it's my 1rst time here i'm asking about a little issue that i face i added a ksh script that echo " please insert your name " and store the output to a login.log file. the script is working fine with normal telnet but Xstart is not working... (8 Replies)
Discussion started by: islam.said
8 Replies
Login or Register to Ask a Question