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
 * Stopping Sympa task manager task_manager
 * Stopping Sympa mailing list archive manager archived
 * Stopping Sympa mailing list manager sympa
 ... 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.
  • 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. – Valentin Bajrami 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

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.

| 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 – Valentin Bajrami Nov 1 '13 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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