Sponsored Content
Top Forums Shell Programming and Scripting Capture output of program to file with limited filesize Post 69187 by Perderabo on Tuesday 12th of April 2005 11:27:33 PM
Old 04-13-2005
I can see both sides of this. reborg has a valid point. If you cap a log file at n lines, you run the risk that line n+1 will be critical information. On the other hand, several times a year I get dragged out of bed because because a server crashed with /var filled due to something like a 5 GB /var/tmp/some_dumb_program.log. It's hard to carefully peruse a 5 GB text file, especially at 3 in the morning, but it's usually my sense that capping the file at, say, half a Gig would not have been a tragedy.

As for if it can be done, yes, but with some caveats. One idea is to create a separate filesystem, say, /scratch. If /scratch is 1 GB, put the file there and it won't exceed 1 GB. You might not have the resources to create a separate filesystem though.

Another option is ulimit, but there is a danger here and a possible obstacle. Your syntax is using &> file which is syntax that I have never seen. But that is close to >& file which would be csh syntax. My csh does not have a ulimit command. Both ksh and bash do. But they need a ulimit facility in the kernel to do that. I don't know if darwin has ulimit. If it does you will need to you a shell with ulimit support. Switching shells is attractive for other reasons: Csh Programming Considered Harmful That's the obstacle...can you use ulimit?

As for the danger, you don't want to simply toss a "ulimit -f 100" or whatever at the top of your script. rsync may need to write a file larger than that just as it syncs. I'm not sure if ulimit affects sockets, but my reading of "man write" suggests that it might. If so, even if the local rsync is reading files and sending them to another system, its socket could be capped. So you want to limit only the log file. In ksh, this should be safe....
rsync options 2>&1 | (ulimit -f 100 ; cat > rsync.log)
The ulimit happens in a subshell which then runs a cat command and the cat command will be limited in the size of file it can create.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Implementing "Time Limited, Trial" version of my program

Hello everyone, I am just looking for ideas on how I can implement a demo version of my program which will be available in unix environment (solaris and linux). So what I have in mind is to either implement a limited-time version (trial version expires after 30 days) or a limited-number... (4 Replies)
Discussion started by: the_learner
4 Replies

2. UNIX for Advanced & Expert Users

Capture output to file and printer

Hi All : I wanted a unix command by which I could be able to print the output to a file and at the same time to a printer. Any help will be greatly appreciated. Regards, Ramamurthy Dasari (1 Reply)
Discussion started by: rdasari
1 Replies

3. Shell Programming and Scripting

capture output of file and send last string thereof to new file

Hello, If I run a program from within shell, the output is displayed in the command line terminal. Is there a way I can capture that output and choose only the very last string in it to send it to a new file? Thank you (6 Replies)
Discussion started by: Lorna
6 Replies

4. Shell Programming and Scripting

Capture Shell Script Output To A File

Hi, I am running a shell script called dbProcess.sh which performs shutdown and startup of various Oracle instances we have.At the time of execution the script produces the following output to the command line window $./dbProcess.sh stop #### Run Details ###### Hostname : server-hop-1... (4 Replies)
Discussion started by: rajan_san
4 Replies

5. Programming

capture key board events using C program

hi This is mahesh please can any one post source of 'c'. to capture key board events. thank u (1 Reply)
Discussion started by: smahesh2007
1 Replies

6. Shell Programming and Scripting

How to capture RC from SAS Program into K-shell

I am running a SAS program within K-shell. This SAS program gives me return code of 3000. However, when I check return code in my K-shell, it displays RC=2. Can someone tell me how to capture RC from SAS to K-shell? Thanks. Pramodini (2 Replies)
Discussion started by: Pramodini Rode
2 Replies

7. Shell Programming and Scripting

How to capture output to log file

Hi I have a script that will run multiple unix & sql commands. I want to see the output as well as capture it to a log file for further analysis. Is there an easy way to do that instead of adding "tee -a logfile" on everyline or even on the execute line (i.e. script | tee -s logfile). Thanks (1 Reply)
Discussion started by: nimo
1 Replies

8. Shell Programming and Scripting

Want ro capture the debug in output file

I want to capture the debug for the below command in output file . i tried like this but its not working: sh -xv <scriptname> >> output.log i want the output in a log file. Anyone plz help in this (2 Replies)
Discussion started by: chakkaravarthy
2 Replies

9. Shell Programming and Scripting

how to invoke external program and capture its output

Hi all, I am using an external binary to view memory starting from a specific address and i want to automate this via PERL however there are problems. Hope you can help me ..thx The output of the programme is like below: bash-3.2$ mem_disp 12B21D20 100 Opening RO Data Memory File scp.ro... (4 Replies)
Discussion started by: ekckabatop
4 Replies

10. Shell Programming and Scripting

Capture output of open pipe to a file in perl

Hi, I am trying to capture the output of the an open pipe in perl. but I am not sure how to do this. can some one please help me do that? Below is the script I am using (2 Replies)
Discussion started by: ahmedwaseem2000
2 Replies
ULIMIT(3)						   BSD Library Functions Manual 						 ULIMIT(3)

NAME
ulimit -- get and set process limits LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <ulimit.h> long ulimit(int cmd, ...); DESCRIPTION
The ulimit() function will get and set process limits. Currently, this is limited to the maximum file size. The cmd argument is one of the following: UL_GETFSIZE will return the maximum file size of the current process, in units of 512-byte blocks. UL_SETFSIZE will attempt to set the maximum file size of the current process and its children, using the second argument (expressed as a long). RETURN VALUES
Upon successful completion, ulimit() returns the value requested; otherwise, the value -1 is returned and the global variable errno is set to indicate the error. ERRORS
The ulimit() function will fail if: [EINVAL] The command specified was invalid. [EPERM] The limit specified to ulimit() would have raised the maximum limit value, and the caller is not the super-user. SEE ALSO
getrlimit(2) STANDARDS
The ulimit() function conforms to IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
The ulimit() function first appeared in FreeBSD 5.0. BUGS
The ulimit() function provides limited precision for setting and retrieving process limits. If there is a need for greater precision than the type long provides, the getrlimit(2) and setrlimit(2) functions should be considered. BSD
January 4, 2003 BSD
All times are GMT -4. The time now is 05:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy