HowTo: logging to file or stdout

HowTo: logging to file or stdout

Post by Rea » Sat, 15 May 1999 04:00:00



Hello everybody,

I'm looking for a way to redirect output to a file OR stdout using a
variable. Imagine something like the following command :

     tar -xf some-software.tar >> ${LOGFILE_NAME}

There are 3 possible values for LOGFILE_NAME :
  1. a filename       :  for logging to a file
  2. the null-device  :  for ignoring all output
  3. standard output  :  for 'normal' display

Option 1 and 2 are respectively a filename and /dev/null - both are true
for all Unix flavors. What can I use for the 3rd option ?  

I'm usually on a Digital Unix system, where theoretically /dev/fd/1
should work but this device doesn't exist by default (see "man fd"). Nor
can I use redirection ( > ) character in a variable.

Anybody any great ideas ?   Thank very much in advance.

Cheers,
Real
--

[ Please, also sent your reply directly by email, otherwise I might ]
[ miss your reply. Thanks.                                          ]

 
 
 

HowTo: logging to file or stdout

Post by Alex Baril » Sat, 15 May 1999 04:00:00




> Hello everybody,

> I'm looking for a way to redirect output to a file OR stdout using a
> variable. Imagine something like the following command :

>      tar -xf some-software.tar >> ${LOGFILE_NAME}

> There are 3 possible values for LOGFILE_NAME :
>   1. a filename       :  for logging to a file
>   2. the null-device  :  for ignoring all output
>   3. standard output  :  for 'normal' display

> for all Unix flavors. What can I use for the 3rd option ?

echo "this will be printed on your current tty" > `tty`

Mind backticks around tty command.

Cheers,
Alex.
--
Before the accident, I even could not spell UNIX

--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---

 
 
 

HowTo: logging to file or stdout

Post by Sriranga Veeraraghava » Sat, 15 May 1999 04:00:00



> There are 3 possible values for LOGFILE_NAME :
>   1. a filename       :  for logging to a file
>   2. the null-device  :  for ignoring all output
>   3. standard output  :  for 'normal' display

> Option 1 and 2 are respectively a filename and /dev/null - both are true
> for all Unix flavors. What can I use for the 3rd option ?  

For case 3 try something like:

LOGFILE_NAME=`tty`

This should work on most unicies (works on Solaris/Linux).  Normally
tty is located in /usr/bin/tty, but it might also be /bin/tty.


 
 
 

HowTo: logging to file or stdout

Post by Eric Amic » Sat, 15 May 1999 04:00:00



> Hello everybody,
> I'm looking for a way to redirect output to a file OR stdout using a
> variable. Imagine something like the following command :
>      tar -xf some-software.tar >> ${LOGFILE_NAME}
> There are 3 possible values for LOGFILE_NAME :
>   1. a filename       :  for logging to a file
>   2. the null-device  :  for ignoring all output
>   3. standard output  :  for 'normal' display
> Option 1 and 2 are respectively a filename and /dev/null - both are true
> for all Unix flavors. What can I use for the 3rd option ?  

Assuming "normal display" means sending it to the screen and not to
standard output, use /dev/tty.

--
Eric Amick
Columbia, MD

 
 
 

1. file descriptor Q, redirecting stderr and stdout to stdout and file.

Hi,

I have a Bourne shell script, and I am trying to send the stdout and
stderr to a file and stdout.

My script looks something like this....

commmand << EOF > syn2gcf.${TODAY}.log 2>&1
other_commands
EOF

This sends the stdout and stderr to the log file. I would like to see
the same on my screen too.

thanks inadvance.

ishaq

Sent via Deja.com http://www.deja.com/
Before you buy.

2. unix hacking

3. Problem with redirecting stdout and stderr to log file

4. help with connecting two networks

5. Writing ksh stdout to both file and stdout?

6. CONFLICT running BIND and other TCP/IP-services on Linux

7. Redirect Netsite Log files to stdout or a program?

8. CD-RW drives

9. C shell log files? STDOUT & STDERR

10. HOWTO Apache Log Files into a single LogFile??

11. Howto: do not log some hosts in access file

12. howto logging mail to /var/log/maillog

13. How can I split a log file into several log files?