nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

shell script to send mail for each login.

This is a discussion on shell script to send mail for each login. within the Shell scripting forums, part of the Development/Scripting category; Hi Everybody, Recently i wrote a script to send mail for each login to my server, as i wanted to ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 11-27-2007, 11:13 AM
Junior Member
User
 
Join Date: Nov 2007
My distro: RedHat Linux 4
Posts: 9
Rep Power: 0
ephdia is on a distinguished road
Lightbulb shell script to send mail for each login.

Hi Everybody,
Recently i wrote a script to send mail for each login to my server,
as i wanted to send mail at the moment of every login i put this script to /root/.bashrc
and it is sending mail only for root logins.now,the problem raisen that i couldn't use scp with this servers.
i don't know is the script correct or not.Please help me to find out the cause of the problem....or any other script to make it work effectively.....Please help...


&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&
#!/bin/bash
echo `last $i | head -1 | awk '{print $1" "$3" "$4" "$5" "$6" "$7}'`|while read output;
do
echo $output
ip=$(echo $output | awk '{print $2}' )
on=$(echo $output | awk '{print $3" "$4" "$5}' )
at=$(echo $output | awk '{print $6'} )
echo "User logged in to $(hostname) server from $ip on $on at $at"|mail -s "Alert from server $(hostname)" xxxx@example.com
done
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&


Thanks in advance.,
Ephdia
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-27-2007, 04:38 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 481
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

So you want script that can email when user login via scp?
__________________
May the force with you!
Reply With Quote
  #3 (permalink)  
Old 11-27-2007, 04:42 PM
Junior Member
User
 
Join Date: Nov 2007
My distro: RedHat Linux 4
Posts: 9
Rep Power: 0
ephdia is on a distinguished road
Lightbulb

I would like to know whether is the script correct one? and solution to use my scp as normal.

Thanks,
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Script to monitor a particular directory and send out e-mail.... nageshms Shell scripting 1 02-11-2008 02:01 PM
shell scripting + send mail with header ephdia Shell scripting 0 11-27-2007 11:29 AM
send mail installation and configuration jhn_daz@yahoo.com Mail Servers 1 11-01-2007 09:37 AM
send mail attachment solaris K.R. Solaris/OpenSolaris 1 02-01-2007 07:05 PM
Require Shell Script Which sends all server info on mail puppen Linux software 3 10-25-2006 08:07 PM


All times are GMT +5.5. The time now is 04:50 AM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36