# Redirect ouput to /dev/null when restarting apache13



## clinty (Mar 5, 2009)

Hello.

I use apache13 port. When I need to restart it, I use /usr/local/etc/rc.d/apache.sh restart.

I have some scripts to create websites (install apache vhosts in a directory, for example). And I need to restart Apache automatically in this script, without print outputs (except errors).

However, I always have outputs:


```
/usr/local/etc/rc.d/apache.sh restart 2> /dev/null
Processing config directory: /usr/local/etc/apache/apps/
 Processing config file: /usr/local/etc/apache/apps/mysql
 Processing config file: /usr/local/etc/apache/apps/stat
Processing config directory: /usr/local/etc/apache/sites/
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/wwww.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
 Processing config file: /usr/local/etc/apache/sites/www.site.net
Processing config directory: /usr/local/etc/apache/ssl/
 Processing config file: /usr/local/etc/apache/ssl//www.site.net
Processing config directory: /usr/local/etc/apache/domains_save/
Processing config directory: /usr/local/etc/apache/domains_temp/
 Processing config file: /usr/local/etc/apache/domains_temp/www.site.net
 Processing config file: /usr/local/etc/apache/domains_temp/www.site.net
 Processing config file: /usr/local/etc/apache/domains_temp/www.site.net
 Processing config file: /usr/local/etc/apache/domains_temp/www.site.net
 Processing config file: /usr/local/etc/apache/domains_temp/www.site.net
 Processing config file: /usr/local/etc/apache/domains_temp/www.site.net
```

(I remplaced site names by http://www.site.net)

As you can see, I have many vhosts files. And I want to mask these ouputs (only show errors). I made a apachectl configtest before for don't restart Apache if errors where found.

When I append a > /dev/null at /usr/local/etc/rc.d/apache.sh restart, these outpurs appears. If I append a 2> /dev/null, too.

I do not have this 'problem' with /etc/rc.d/named restart > /dev/null. Only with apache13 port rc script.

Do you have any ideas?

Thanks a lot.

Regards,


----------



## DutchDaemon (Mar 5, 2009)

If you want to see errors only, you should use 


```
/usr/local/etc/rc.d/apache.sh restart > /dev/null
```

This will not redirect the error channel (#2) to /dev/null, only the standard output (#1).

You are sending the errors to /dev/null, so you only see standard output. The other way around ..

You can test which channel contains what like this:


```
/usr/local/etc/rc.d/apache.sh restart 1>channel1 2>channel2
```


----------



## clinty (Mar 5, 2009)

No. I said in my post :
_When I append a > /dev/null at /usr/local/etc/rc.d/apache.sh restart, these outpurs appears_

That's the problem. I tried 2> /dev/null for testing...

In my case, /usr/local/etc/rc.d/apache.sh restart > /dev/null prints this output.


----------



## SirDice (Mar 5, 2009)

What shell are you using?


----------



## clinty (Mar 5, 2009)

Usually, /usr/local/etc/rc.d/mydaemon > /dev/null works and prints no ouputs (except errors).

So, I do not understand why with apache13 (and only it), outputs are already printed... I have this at the end of my httpd.conf:


```
Include /usr/local/etc/apache/apps/
Include /usr/local/etc/apache/sites/
Include /usr/local/etc/apache/ssl/
Include /usr/local/etc/apache/domains_save/
Include /usr/local/etc/apache/domains_temp/
```

The result of these includes is already printed when I restart the rc script.

Thanks for your advices.

Regards,


----------



## clinty (Mar 5, 2009)

SirDice said:
			
		

> What shell are you using?


I'm using /bin/tcsh. and /bin/sh in my scripts. With both, the result is the same.


----------



## DutchDaemon (Mar 5, 2009)

Does


```
/usr/local/etc/rc.d/apache.sh restart 1>channel1 2>channel2
```
 still produce on-screen output? Notice that apache.sh contains a lot of extra and external system calls, which should conform to how you redirect your output, but maybe they don't.


----------



## clinty (Mar 5, 2009)

Hummm... Other informations:

A rc script always print:

```
Stopping daemon_name.
Waiting for PIDS: pid_number, pid_number, pid_number.
Starting daemon_name.

And other informations. In my case, informations about my vhosts included.
```

When I append a > /dev/null, informations about 'stopping' and 'starting' are not printed. So, my redirect to /dev/null works. But other informations are already printed.

That's why I don't understand. rc informations are on the standard output...


----------



## SirDice (Mar 5, 2009)

On tcsh 2> won't work. IIRC it's >& but this will route stderr and stdout to the same thing.


----------



## clinty (Mar 5, 2009)

DutchDaemon said:
			
		

> Does
> 
> 
> ```
> ...


Yes, I think apache13 rc script could countains external system calls. In this case, when I call apache.sh, is a solution exist for not print ouput?


----------



## DutchDaemon (Mar 5, 2009)

Well, there are a lot of these lines in apache.sh already (these are from apache22, though):


```
/sbin/kldstat -v | grep accf_http [B]>/dev/null 2>&1[/B]
/sbin/kldload accf_http [B]2> /dev/null[/B]
```

Looks like you have to /dev/null everything yourself, because apache.sh executes these commands in a new shell by the looks of it.


----------



## clinty (Mar 5, 2009)

The problem is the same when I use 'apachectl startssl > /dev/null': outputs are printed.


----------



## DutchDaemon (Mar 5, 2009)

Both apache.sh and apachectl (which is a shell script) call httpd -k, so they perform the same tasks which result in the same output.


----------



## clinty (Mar 5, 2009)

Erf. And is there a solution to mask (or redirect to /dev/null) httpd -k outputs? (when it is called by apachectl or apache rc script)


----------



## clinty (Mar 5, 2009)

```
/usr/local/sbin/httpd -DSSL > /dev/null
```
always prints output messages


----------



## DutchDaemon (Mar 5, 2009)

clinty said:
			
		

> Erf. And is there a solution to mask (or redirect to /dev/null) httpd -k outputs? (when it is called by apachectl or apache rc script)



IMO, only by adding *> /dev/null* to every line in those scripts where commands are executed (there's more than just httpd -k in there), which will become rather pointless, because a port upgrade will simply replace them with new versions.


----------



## clinty (Mar 5, 2009)

DutchDaemon said:
			
		

> IMO, only by adding *> /dev/null* to every line in those scripts where commands are executed (there's more than just httpd -k in there), which will become rather pointless, because a port upgrade will simply replace them with new versions.


apachectl and apache.sh rc script call /usr/local/sbin/httpd.
However, a /dev/null appened to httpd -DSSL does not solve the problem. 
A VAR=`/usr/local/sbin/httpd -DSSL` prints output messages :\

Really, I do not understand. httpd is a binary. All scripts call it. The problem come with httpd binary.


----------



## DutchDaemon (Mar 5, 2009)

It's not a FreeBSD issue, I think. Try at an Apache forum, maybe.


----------



## osx-addict (Mar 5, 2009)

If you're in tcsh, try this (or replace apachectl with the offending script in question) :


```
% apachectl restart >&output.log
```

That should redirect everything to the output.log file


----------



## clinty (Mar 6, 2009)

Wa, this command works! I didn't know it!
Thanks a lot. Now, I can make a apachectl >&/dev/null


----------



## DutchDaemon (Mar 6, 2009)

So separating/redirecting channels isn't even possible in tcsh? Tsk.


----------



## osx-addict (Mar 6, 2009)

DutchDaemon said:
			
		

> So separating/redirecting channels isn't even possible in tcsh? Tsk.



Correct.. It's a limitation of tcsh.:\


----------

