How to redirect (and append) standard output/error to a log file?

How to redirect (and append) standard output/error to a log file?

Post by Jim Bancrof » Wed, 26 Feb 2003 03:35:08



Hi all,

    I have a shell script which runs various command (the bash shell), and
I'm looking to output the standard error and output to a log file.  I
believe you can output both streams to a file using something:

run_my_command >& logfile

..but how can I *append* the output of various commands to the logfile?  If
I redirect the next command using >&, then the logfile is overwritten.  I
tried ">>&", but all that gave me is an error message, so I must be doing
something wrong.

TIA,

-Jim

 
 
 

How to redirect (and append) standard output/error to a log file?

Post by Barry Margoli » Wed, 26 Feb 2003 03:48:51




>    I have a shell script which runs various command (the bash shell), and
>I'm looking to output the standard error and output to a log file.  I
>believe you can output both streams to a file using something:

>run_my_command >& logfile

>..but how can I *append* the output of various commands to the logfile?  If
>I redirect the next command using >&, then the logfile is overwritten.  I
>tried ">>&", but all that gave me is an error message, so I must be doing
>something wrong.

"command >& file" is just a shortcut for "command > file 2>&1", but that
abbreviation doesn't exist for appending.  The solution is to spell it out
the long way:

run_my_command >> logfile 2>&1

--

Genuity Managed Services, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

How to redirect (and append) standard output/error to a log file?

Post by Jim Bancrof » Wed, 26 Feb 2003 07:55:52


Thanks very much-- just what I needed.

-Jim

 
 
 

1. redirecting standard output and standard error

Hi,

I want to call a command using C programmatically using execv, but I
also want to capture the standard output and standard error to files I
specify through command line args.  I want to use the file descriptors
0, 1, and 2 appropriately for this, and I understand I should probably
call a fork()
when calling the execv so my program can return successfully.  But
from there,
I'm not sure where to start.  I think I want to probably use dup2 so I
can redirect the descriptors to files I open.  Maybe create a pipe
from the child process to the parent process, where I pass through the
pipe are the results of the command call ??  Just need some guidance
and want to make sure I'm in the right direction.  Thanks.

2. command (mt) to fwd to end of tape

3. How to redirect standard error to standard output (in csh)?

4. How to get children of a widget

5. Redirecting standard output and error to a file

6. MacTCP printing through a Linux (Unix) box

7. How to redirect standard output and error messages in a make file

8. Q: PPP setup - SOS before giving up!!!

9. ambiguous output redirect error when appending

10. how to direct standard output and error output to the same file in tcsh

11. can not redirect the standard output to a file

12. Redirecting standard output and error

13. How can I fork output to log file and standard out?