Link to home
Start Free TrialLog in
Avatar of speednow
speednow

asked on

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.




Avatar of F. Dominicus
F. Dominicus
Flag of Germany image

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
Avatar of ppfoong
ppfoong


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


Sorry, the cat command should be:

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

ASKER CERTIFIED SOLUTION
Avatar of fpintos
fpintos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
fpintos
what do you think my use of ssh does?

Friedrich

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.


Friedrich,

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

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

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.