Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to restart a system process through cron and getting emailed the startup output of the process. I thought redirecting STDOUT and SDTERR to /dev/null would "silence" the output but alas, this has not work. How can I get cron to silently restart this service? crontab entry:

0 6 * * * service sympa stop &>/dev/null; service sympa start &> /dev/null

sample output from restart email:

 Stopping Sympa bounce manager bounced
   ...done.
 * Stopping Sympa task manager task_manager
   ...done.
 * Stopping Sympa mailing list archive manager archived
   ...done.
 * Stopping Sympa mailing list manager sympa
   ...done.
 ... waiting Prototype mismatch: sub Lock::LOCK_SH () vs none at /home/sympa/bin/Lock.pm line 38.
Constant subroutine LOCK_SH redefined at /home/sympa/bin/Lock.pm line 38.
Prototype mismatch: sub Lock::LOCK_EX () vs none at /home/sympa/bin/Lock.pm line 39.
Constant subroutine LOCK_EX redefined at /home/sympa/bin/Lock.pm line 39.
Prototype mismatch: sub Lock::LOCK_NB () vs none at /home/sympa/bin/Lock.pm line 40.
Constant subroutine LOCK_NB redefined at /home/sympa/bin/Lock.pm line 40.
share|improve this question
    
Your redirections are about-face; try service sympa stop >&/dev/null, and the other likewise. At the moment not only are you only redirecting STDOUT (and thus getting STDERR by mail), you're backgrounding the commands as well, which means they will run concurrently not consecutively - not at all what you want, I suspect. –  MadHatter Nov 1 '13 at 13:47
    
Actually, &>word is the preferred (according to the bash man page) way to write that redirect. >&word will also work but is not preferred. –  Etan Reisner Nov 1 '13 at 13:56
    
Thanks for taking the time to answer.>&/dev/null produces /bin/sh: Syntax error: Bad fd number –  Server Fault Nov 1 '13 at 14:01
3  
I think you'd want service sympa stop >/dev/null 2>&1. The first command sends stdout to /dev/null then 2>&1 causes stderr to be sent to where stdout is going which is /dev/null resulting in supressing output. –  val0x00ff Nov 1 '13 at 14:10
1  
Ahhhh, yeah that was it. Adding SHELL=/bin/bash fixed it. Thanks! –  Server Fault Nov 1 '13 at 14:12

1 Answer 1

up vote 5 down vote accepted

I think you'd want the following line

service sympa stop >/dev/null 2>&1.

The first command sends stdout to /dev/null then 2>&1 causes stderr (standard error) to be sent to where stdout(standard output) is going which is /dev/null resulting in supressing output.

share|improve this answer
1  
Nice work, val0x00ff; serve me right for thinking short cuts! –  MadHatter Nov 1 '13 at 14:26
1  
@MadHatter it makes it more readable in my opinion and maybe easier to remember when referring to stderr or stdout –  val0x00ff Nov 1 '13 at 14:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.