Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Need to write a shell script which gives a message to the adminitrator/root via email or by message on the console, whenever a user logs on to the system. Can anyone suggest as to how I go about doing this ??

Pretty simple either
echo "message goes here | write root
or
echo "message goes here" | mail -s "subject" e-"mailaddress"

dinesh,
the script from LANkrypt0 is ok, you should place it under /etc/profile {which will be executed for every user logged in via telnet}.
This does not include an FTP loggin or graphical loggin.
But also this is possible do you would like to know how ?
No RISK no funRegards Frank

Hi frank...would it work for ssh also? And
id like to know what needs to be done for
graphical or FTP logins.thanks
mux

Hi Frank & LANkrypt0,
I wanted to know if one can read the sylog file to determine the user log in information and email or notify the root about the user who has logged in.like tail -f syslog | grep telnetd and then finding the user who logged in and then sending an email.
Can you help me regarding this ...

mux,
the default configuration of ssh uses also /etc/profile.
But in the end it depends on the detail configuration of your ssh.mux & Dinesh,
to see other loggins like PCNFS, FTP, XTERM,
you can use the last command grep for the interested time slice and send the resault to root.
e.g.
SearchDate=`date +"%b %d"`
last |grep "$SearchDate"|awk '{system (" echo login: " $1 " at " $4,$5,$6 ) } 'put this lines into a script which will executet in your requierd time slice (once a day ?)
or if you would like to have a kind of real time monitoring use the following as a script (is a endless loop):
Luser=`last | head -1`
Vuser=$Luser
while :
do
Luser=`last | head -1`
if [ "${Luser}" != "${Vuser}" ]
then
echo $Luser > /tmp/mytmp
mail a1xrdb1@cipofdc1 < /tmp/mytmp
Vuser=$Luser
fi
done
You can modify the script to use the syslog file also very quick.Have Fun
Frank

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |