getting remote ip in bash script

Eric R. rossiter at discoverynet.com
Thu Jan 30 21:27:40 CST 2003


Hey LugNuts,

I'm trying to whip up a bash script that will report to the user at 
logon, the logon id, IP they came from, etc.

I've tried putting this in /etc/motd, but that just shows everything... 
(echo statements, etc.) and I don't understand why.

So, I'm just putting this little script in the .bashrc files for each 
user and it fires right after motd is displayed. (gotta be a better way).

here's what I have so far:

#!/bin/bash

# Script to print user information who currently login , current date & time
#

#clear
echo -e "Today is: 033[32m`date`033[0m"
echo -e "Your login ID is: 033[31m `echo "$USER"`033[0m"
echo -e "Your host is: 033[35m `echo "$HOSTNAME"`033[0m"
echo -e "033[36mYour info has been logged.033[0m"

The codes change color.  $HOSTNAME obviously gives me the host name I 
just logged onto, I want the host (or IP, or both) I just logged in FROM.

I tried netstat, and piped it to cut -c45-65 but that gave me every 
connection that netstat sees... LOL!!! not the desired effect!!

any help would be appreciated,

E




More information about the Kclug mailing list