LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices

Reply
 
Search this Thread
Old 04-01-2010, 09:50 AM   #1
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Rep: Reputation: 32
If Remote Login then Mail


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.
 
Old 04-01-2010, 10:26 AM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,009
Blog Entries: 5

Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
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).
 
Old 04-06-2010, 05:32 AM   #3
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by MensaWater View Post
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.
 
Old 04-06-2010, 05:46 AM   #4
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Hello,

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
 
Old 04-06-2010, 05:53 AM   #5
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by EricTRA View Post
Hello,

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?

Thanks in advance.

Regards,
Ashok.
 
Old 04-06-2010, 05:59 AM   #6
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Hello,

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.

Kind regards,

Eric
 
Old 04-06-2010, 06:28 AM   #7
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
Eric,

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.

Kind Regards,
Ashok.
 
Old 04-06-2010, 06:45 AM   #8
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Hello,

Of course you can use sendmail to do the job! With Linux YOU have the choice and you're in control, so you can use whatever works for you . Since I'm not familiar with sendmail I looked up some things in Google and these should help you on your way:
http://www.ozzu.com/unix-linux-forum...il-t29690.html
http://www.akadia.com/services/sendmail_relay.html

Kind regards,

Eric
 
Old 04-06-2010, 07:42 AM   #9
DrLove73
Senior Member
 
Registered: Sep 2009
Location: Srbobran, Serbia
Distribution: CentOS 5.5 i386 & x86_64
Posts: 1,118
Blog Entries: 1

Rep: Reputation: 129Reputation: 129
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.
 
Old 04-06-2010, 07:46 AM   #10
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
As I said before, I knew nothing about POP3, SMTP, MTA. So, I request you to give some information about the terms when posting.
 
Old 04-06-2010, 09:50 AM   #11
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,759

Rep: Reputation: 2612Reputation: 2612Reputation: 2612Reputation: 2612Reputation: 2612Reputation: 2612Reputation: 2612Reputation: 2612Reputation: 2612Reputation: 2612Reputation: 2612
Quote:
Originally Posted by ashok.g View Post
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.
 
Old 04-06-2010, 09:53 AM   #12
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,009
Blog Entries: 5

Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
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.
 
Old 04-08-2010, 04:18 AM   #13
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
Hello MensaWater,

I have made my .bash_profile as
Code:
# .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!

Thanks in advance,

Kind Regards,
Ashok.
 
Old 04-08-2010, 08:37 AM   #14
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,009
Blog Entries: 5

Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
Code:
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.
 
Old 04-08-2010, 09:03 AM   #15
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
[QUOTE=MensaWater;3928534]
Code:
echo "$USER logged in to system." |mail -s "$USER Logged in to your system" root@localhost
Thanks alot!
I am getting all expect that $user. It's printing a space.
 
  


Reply

Tags
login, mail, remote


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Procmail: forwarding mail to remote mail account Cadmium Linux - Software 2 01-14-2010 01:05 PM
command line email client to send mail to remote mail server dhanju Linux - Software 1 03-07-2008 06:37 AM
how to make remote login and remote installation via libssh vdx Programming 5 09-10-2007 10:23 PM
Remote login with SSH, but display on remote computer. brodin Linux - Software 3 09-09-2007 03:01 AM
remote login screen but need local login lastkey Ubuntu 0 12-13-2006 01:41 AM


All times are GMT -5. The time now is 04:50 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration