Linux mail(x) command. Can't open or use. Just spits out old message and returns to prompt

jaydisc asked:

(Debian Squeeze)

I was working on a shell script that piped output to the mail command. I must have done something wrong, as I am no longer able to use the command for anything. Even if I type “mail” with no arguments, it just spits out what appears to be the content I previously tried to email, but it then just returns me to a prompt. The same output occurs regardless of which arguments I use with the command.

We do not use local mail storage, and I have deleted all of the user files in /var/mail and /var/spool/mail (one is a link to the other), but for the life of me, I cannot figure out how to get use of this command back.

I’m struggling with any kind of searching for this problem as the search terms seem way too vague.

My answer:

I suspect that at some point you accidentally did something like:

....command... > /usr/bin/mail

instead of

....command... | /usr/bin/mail

thus replacing /usr/bin/mail with a copy of some data.

I would suggest that you reinstall the mail program. Because Debian ships several alternatives, you can find the one you have installed with:

root@www:~# ls -l /usr/bin/mail
lrwxrwxrwx 1 root root 22 2011-04-04 02:48 /usr/bin/mail -> /etc/alternatives/mail

root@www:~# ls -l /etc/alternatives/mail
lrwxrwxrwx 1 root root 18 2011-04-04 02:48 /etc/alternatives/mail -> /usr/bin/bsd-mailx

So the mail program is really /usr/bin/bsd-mailx on this system. Let us find out which package it came from:

root@www:~# apt-file search /usr/bin/bsd-mailx
bsd-mailx: /usr/bin/bsd-mailx

And finally we will reinstall that package.

root@www:~# apt-get install --reinstall bsd-mailx
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 1 not upgraded.
Need to get 155kB of archives.
After this operation, 0B of additional disk space will be used.
Do you want to continue [Y/n]?

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.