How to empty Email of an User in redhat

Need to empty the email box of a user on a Red Hat 8 Server.

Servers using Sendmail.

Access: SSH

Dont know what commands to execute and know how much email does that account  has.




speednowAsked:
Who is Participating?
 
fpintosCommented:
The simplest way is use ssh to login to the server and type:

 : >/var/spool/mail/user_login_name

This will empty the user mailbox and leave an empty file behind.
0
 
fridomCEO/ProgrammerCommented:
The incoming mail is usually saved in /var/mail or /var/spool for /var/spool/mail  in file names after the login.

So you can run a
ssh your_remote_login@remote_location "sh -c > /var/mail/login_name"
or
ssh your_remote_login@remote_location rm -f /var/mail/login_name

Of course you need an account which is allowed to write that, it's IMHO not a good idea to allow root login (even with ssh) so you could setup sudo on the remote machine to do the actual delting.

Friedrich
0
 
ppfoongCommented:

By default, the email files are in /var/spool/mail directory, one file per user, filename follows the username.

You can remove the mails by either of the below:

cp /dev/null /var/spool/mail/username
cat /dev/null /var/spool/mail/username
rm -f /var/spool/mail/username

0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
ppfoongCommented:

Sorry, the cat command should be:

cat /dev/null > /var/spool/mail/username

0
 
fridomCEO/ProgrammerCommented:
fpintos
what do you think my use of ssh does?

Friedrich

0
 
prashsaxCommented:
Just one thing to remember, don't just delete all the mails, if possible move them and store it somewhere else for few days. You never know, when the user or someone else will ask for those mails.


0
 
fpintosCommented:
Friedrich,

ssh your_remote_login@remote_location "sh -c > /var/mail/login_name"

will give sh: -c: option requires an argument........

0
 
fpintosCommented:
Friedrich,

FYI, you don't need to fork another shell "sh -c" in your remote ssh to empty a file, using the immediate shell (spawn by sshd) and  ":" syntax is faster and more efficient.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.