Red HatThis forum is for the discussion of Red Hat Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hi folks,
I have some simple practical requirement to receive a mail if someone logged to my system.
I think we can see who are logged into our system using the command who or finger or w. But I want to get a mail as soon as a guy logged into my system.
How can I do that?
Any help is highly appreciated.
You could add a mail command to their profile or to the system profile in etc (e.g. .profile, .bashrc in user's home or /etc/profile or /etc/bashrc). The files in /etc affect all users using the shell for which they were defined. (e.g. if they were using csh you could use /etc/login).
You could add a mail command to their profile or to the system profile in etc (e.g. .profile, .bashrc in user's home or /etc/profile or /etc/bashrc). The files in /etc affect all users using the shell for which they were defined. (e.g. if they were using csh you could use /etc/login).
Thanks for your reply.
Could you expain me more with an example.
Also I'm able to send mail to only root but not to other domains like yahoo.com or gmail.com.
You'll need to set up a MTA (mail transfer agent) like Postfix in order to relay mail to Gmail or Yahoo. But be aware that they don't allow relaying from dynamic IP, so if you're connecting from behind a regular ADSL connection it'll probably fail.
You'll need to set up a MTA (mail transfer agent) like Postfix in order to relay mail to Gmail or Yahoo. But be aware that they don't allow relaying from dynamic IP, so if you're connecting from behind a regular ADSL connection it'll probably fail.
Kind regards,
Eric
Hi Eric,
Many thanks for your reply.
I don't know anything about MTA, ADSL.
Can you guide me so that I can send a mail to any domain?
You can have a look at this easy to follow step by step guide on HowToForge to setup Postfix. Of course you'll have to install it first on your server.
I am using RHEL AS 4.
We have sendmail command in linux to send a mail to some domain.
It's configuration file are /etc/mail/sendmail.mc and /etc/mail/senmail.cf. Can we modify these two files so that we can send mails to other domain or its mandatory to use Postfix and MTA.
To relay your mail to any domain, you need to use SMTP server of your ISP. I believeyou will set this in someting like "relayserver" option in either MTA. It will accept your mail and forwarded it to designated destination.
You can also send mail locally to root, and then either use POP3 server on that machine and pull e-mails via your E-Mail client, or create redirection file that will automatically redirect any mail that root receives to another account on any domain.
As I said before, I knew nothing about POP3, SMTP, MTA. So, I request you to give some information about the terms when posting.
And we request you look them up if you don't know. Demanding we go into more detail when answering you, so you don't have to put any effort forth, is very rude.
Google can tell you all this, as well as give you many bash shell scripting examples. Try it.
Ashok - The site is for "help" not "doing it for you".
When you run across terms you're unfamiliar with you should do a Google search to try to gain understanding then ask specific questions when you get stuck.
Generally what you need to do is:
1) Configure sendmail to relay messages to another server.
2) Configure the other server to allow sendmail to relay to it from the first server.
Are you doing this inside a business that has a primary mail server? If so you need to get information from and provide information to the mail administrator. The discussion about POP, DSL etc... is assuming you're doing this from home and trying to get out to the internet. Therefore before posting further questions in addition to doing some basic research you need to tell us more about your environment.
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
mail -s "Someone Logged in to your system" root@localhost;
Now, when anyone logged into my system it will ask for the input to mail command.
How can I overcome this problem?
Please help me!
echo "$USER logged in to system." |mail -s "$USER Logged in to your system" root@localhost
Your email didn't have a body - just a subject and recipient so it went into an interactive session. By piping in a body with the echo command it doesn't go interactive. The $USER variable is the user that logged in so instead of seeing "someone" you see exactly who logged in.
Last edited by MensaWater; 04-08-2010 at 08:38 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.