Operating System - Linux
1828224 Members
2047 Online
109975 Solutions
New Discussion

how to suppress an error in a mail command

 
iinfi1
Super Advisor

how to suppress an error in a mail command

I have written something like this to send me filesystem status every 2 hours. i run this as a cron.

[script]
df -h > /home/ap/fsstatus.txt
uptime >> /home/ap/fsstatus.txt
mail -s "haad-oas1 File System Status" ap@gmail.com < /home/ap/fsstatus.txt
[/script]

when this mail goes through exchange it throws an exception bounce back email with the following text
[bounceback mail contents]
tar: Removing leading `/' from member names
/var/log/messages
[/bounceback mail contents]

how can i avoid this.

thanks
3 REPLIES 3
Matti_Kurkela
Honored Contributor

Re: how to suppress an error in a mail command

You've redirected the standard output (stdout) of your commands to file fsstatus.txt, but the standard error output (stderr) is not redirected.

The messages you're seeing are sent to stderr by the tar command.

The syntax to redirect stderr to a file is "2> somefile" or "2>> somefile", similar to ">" and ">>" used for redirecting stdout. There is also a shorthand "2>&1" which means "send the stderr output to the same place where the stdout is going." The numbers refer to standard file descriptor numbers: stdin is #0, stdout is #1 and stderr is #2.

So you might modify your script like this:
--------
df -h > /home/ap/fsstatus.txt 2>&1
uptime >> /home/ap/fsstatus.txt 2>&1
mail -s "haad-oas1 File System Status" ap@gmail.com < /home/ap/fsstatus.txt
--------

MK
MK
iinfi1
Super Advisor

Re: how to suppress an error in a mail command

oh... ok

i forget the basics too often for comfort.
and further the tar error is being thrown by another script.

thank you Matti
Steven Schweda
Honored Contributor

Re: how to suppress an error in a mail command

> and further the tar error is being thrown
> by another script.

Probably one with a "tar" command in it.
("tar: " was a clue.)

And you could avoid this complaint by
specifying a relative path ("fred") instead
of an absolute path ("/fred") there, which is
generally considered a better practice for
various reasons (which is why "tar" is trying
to "help" you this way).

man tar