Jump to content

Receive email on login

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Crop

Crop

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
When someone logs on as root how can I receive an email? Is there a logon script of sorts that I could run it in?

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
You can a command to your .bashrc script - use the sendmail command.

#3
Guest_ptt3_*

Guest_ptt3_*
  • Guests
Here is the command for it (to execute from .bashrc):

$ /usr/sbin/sendmail email@address <l email.txt

Where email.txt is the email file you want to send as the message.

#4
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Hell, is it that simple to send an email from Linux? Wow..amazing! But what will be the email address that will be displayed as received from? I mean the email address that it was sent from?

#5
Guest_powerspike_*

Guest_powerspike_*
  • Guests
you can even go an easier route.

in the .bashrc file do something like
mail -s "Root Login" <email address>

if you log in as root, and type in export
you can see the varibles that are set in the shell, one of them should be the remote ip address
i can't remember the varible off the top of my head
but if on the command like put in $VARIBLENAME it'll print the contents out, so you could also do something like
mail -s "$VARIBLE1 has logged in as root" <email address>
there's many ways to skin a cat as they say.

#6
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Nice post and great idea powerspike. That variable for SSH is

SSH_CLIENT

which has an output of "::ffff:10.225.66.192 2438 22"

#7
Guest_powerspike_*

Guest_powerspike_*
  • Guests
that one is IPv6 Forumat, but you can see from that, the ip address (IPv4) is 10.225.66.192 (that's a private ip adress space - so jordan was testing it on a local network =). 2438 will be the source connection port (from the machine that made the connection) and 22 is the destination port, 22 in this case is ssh =)