services output oddity

Nils Kassube kassube at gmx.net
Sat Jul 2 20:36:00 UTC 2011


Dave Stevens wrote:
> # service --status-all > servicesrunning.txt
>   [ ? ]  anacron
>   [ ? ]  console-screen.sh
[...]
> given the command line above I would have expected the output text to
> go into a file called servicesrunning.txt, not on screen. But the
> above output is the screen text.
> 
> There IS text in the new file servicesrunning.txt, like this:
> 
> dave at cl28810:~$ cat servicesrunning.txt
>   [ + ]  apache2
>   [ + ]  bind9
[...]

What you see on the screen is sent to the standard error while the 
standard output is sent to your text file. If you want to have both in 
the same file, use this command:

service --status-all > servicesrunning.txt 2>&1

That way the standard error is redirected to the standard output and 
both are redirected to your text file.


Nils




More information about the ubuntu-users mailing list