Hullo there,
I'm trying to prevent a very simple script in cron.hourly from sending mail when it executes.
The script consists of
mount -a > /dev/null
I hoped the output would be directed to a black hole, but it sends a mail every hour as below.
/etc/cron.hourly/checkmounts: mount: knossos:/home already mounted or /nfshome busy mount: xios:/home already mounted or /nfshome-xios busy run-parts: /etc/cron.hourly/checkmounts exited with return code 32
Is the only way to prevent mail output to make the script more complicated with exit codes and whatnot?
Thanks,
Jenny
On Wed, 2007-10-10 at 09:47 +0100, Jenny Hopkins wrote:
Hullo there,
I'm trying to prevent a very simple script in cron.hourly from sending mail when it executes.
The script consists of
mount -a > /dev/null
I hoped the output would be directed to a black hole, but it sends a mail every hour as below.
/etc/cron.hourly/checkmounts: mount: knossos:/home already mounted or /nfshome busy mount: xios:/home already mounted or /nfshome-xios busy run-parts: /etc/cron.hourly/checkmounts exited with return code 32
Is the only way to prevent mail output to make the script more complicated with exit codes and whatnot?
Hi Jenny,
The > only redirects STDOUT, it wont redirect STDERR, which is why you're getting the messages.
Try the following
mount -a 2>&1 > /dev/null
The 2>&1 forces STDERR to goto STDOUT, which you caqn then send to /dev/null.
Hope that helps
Chris
On 10/10/2007, Chris Glover chris@glovercc.plus.com wrote:
mount -a 2>&1 > /dev/null
The 2>&1 forces STDERR to goto STDOUT, which you caqn then send to /dev/null.
I had tried this originally (with the 2>&1 on the other side), and errors stopped for a few days but then restarted. I then tried the leaner version which I posted. I have to be vague here, as the mails go to a client and it's hard working out what, why and when from him :-)
Mark:
See http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html for some useful hints
Thanks for the link.
Jenny
On 10/10/2007, Jenny Hopkins hopkins.jenny@gmail.com wrote:
On 10/10/2007, Chris Glover chris@glovercc.plus.com wrote:
mount -a 2>&1 > /dev/null
The 2>&1 forces STDERR to goto STDOUT, which you caqn then send to /dev/null.
I had tried this originally (with the 2>&1 on the other side), and errors stopped for a few days but then restarted. I then tried the leaner version which I posted. I have to be vague here, as the mails go to a client and it's hard working out what, why and when from him :-)
I start to see (I think): The script in cron.hourly now reads mount -a > chmnt.txt 2> chmnt.txt
but I still get the mail below. Is it because the report is actually coming from cron daemon rather than the checkmounts script?
Cron Daemon to root@localhost.localdomain date 10 Oct 2007 11:17 subject Cron root@dellbox run-parts --report /etc/cron.hourly
run-parts: /etc/cron.hourly/checkmounts exited with return code 32
Many thanks,
Jenny
On Wed, Oct 10, 2007 at 11:41:06AM +0100, Jenny Hopkins wrote:
I start to see (I think): The script in cron.hourly now reads mount -a > chmnt.txt 2> chmnt.txt
but I still get the mail below. Is it because the report is actually coming from cron daemon rather than the checkmounts script?
Cron Daemon to root@localhost.localdomain date 10 Oct 2007 11:17 subject Cron root@dellbox run-parts --report /etc/cron.hourly
run-parts: /etc/cron.hourly/checkmounts exited with return code 32
BING BING BING BING.... it's because of the return code... so, what's the last command that that runs? If it's the mount, then you might want to actually see the output of the mount command - because something is going wrong...
Cheers,
On 10/10/2007, Brett Parker iDunno@sommitrealweird.co.uk wrote:
subject Cron <root@dellbox> run-parts --report /etc/cron.hourly
run-parts: /etc/cron.hourly/checkmounts exited with return code 32
BING BING BING BING.... it's because of the return code... so, what's the last command that that runs? If it's the mount, then you might want to actually see the output of the mount command - because something is going wrong...
Yes, it's the mount script. It throws the error because I'm trying to mount something that is already mounted. That's the point of the script though - if it's not mounted, mount it, otherwise do nothing. The 'doing nothing' wants to include 'including sending me a mail telling me about it'.
Thanks,
Jenny
On Wed, Oct 10, 2007 at 12:21:45PM +0100, Jenny Hopkins wrote:
On 10/10/2007, Brett Parker iDunno@sommitrealweird.co.uk wrote:
subject Cron <root@dellbox> run-parts --report /etc/cron.hourly
run-parts: /etc/cron.hourly/checkmounts exited with return code 32
BING BING BING BING.... it's because of the return code... so, what's the last command that that runs? If it's the mount, then you might want to actually see the output of the mount command - because something is going wrong...
Yes, it's the mount script. It throws the error because I'm trying to mount something that is already mounted. That's the point of the script though - if it's not mounted, mount it, otherwise do nothing. The 'doing nothing' wants to include 'including sending me a mail telling me about it'.
Soooo... add the following magical line to the end of the script: exit 0
That should do it ;)
On 10/10/2007, Brett Parker iDunno@sommitrealweird.co.uk wrote:
Soooo... add the following magical line to the end of the script: exit 0
That should do it ;)
That has done it :-)
Thanks!
Jenny
On Wed, Oct 10, 2007 at 09:47:34AM +0100, Jenny Hopkins wrote:
Hullo there,
I'm trying to prevent a very simple script in cron.hourly from sending mail when it executes.
The script consists of
mount -a > /dev/null
I hoped the output would be directed to a black hole, but it sends a mail every hour as below.
Try:
mount -a > /dev/null 2> /dev/null
The > redirects standard output, the 2> redirects standard error, which is probably where your errors are going to.
J.
On 10/10/2007, Jonathan McDowell noodles@earth.li wrote:
Try:
mount -a > /dev/null 2> /dev/null
The > redirects standard output, the 2> redirects standard error, which is probably where your errors are going to.
Lovely, thanks.
I'll try this.
Jenny
Jenny Hopkins wrote:
mount -a > /dev/null
I hoped the output would be directed to a black hole, but it sends a mail every hour as below.
mount is (correctly) sending errors to stderr (which you're not redirecting). This can be quite a good thing; programs which generate "helpful" comments that you want to lose can be redirected without losing any unexpected errors.
See http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html for some useful hints but mount -a &> /dev/null .. will send all output to /dev/null (the above link shows how to handle the different streams separately if needed).