LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-30-2002, 01:50 PM   #1
Stephanie
LQ Addict
 
Registered: May 2001
Location: Arizona
Distribution: 9.2 Mandy 1.4 Gentoo 5.1 FreeBSD WinXP
Posts: 1,166

Rep: Reputation: 45
Finding what IP address a process starts


This is what my friend sent me today, and I thought maybe one of you smart guys out there could help me and him:

I've got a script that clobbers my process...no biggie, I mofied the script to restart the process. However, sometimes (i.e. when I'm not the one babysititng it) it doesn't restart properly. I'm trying to make sure this is the absolute case and that the process isn't dying on its own (it's not supposed to). I've got trackkers in the script to track when it is run and by whom, only problem is it's typically run by a group account. How do I find out the IP of the terminal running the script? I.E., there is a whoami to find out the user ID, but I want a similar command to insert the IP so I know the actual HUMAN that ran the script since Our IP's are static....

I want :
echo "Script ran at `date` by `whoami` " >>log.log

to become:
echo "Script ran at `date` by `whoami` from `**IP ADDRESS COMMAND`" >>log.log

so it prints in the log:
Script ran at 10 pm sun oct 27 2002 by johndoe from 255.255.255.255
 
Old 10-30-2002, 03:31 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Use the tty command to find out what terminal the user came in on, then you can lookup the terminal in the output of the 'w' command to find the IP.
 
Old 10-31-2002, 12:01 PM   #3
Stephanie
LQ Addict
 
Registered: May 2001
Location: Arizona
Distribution: 9.2 Mandy 1.4 Gentoo 5.1 FreeBSD WinXP
Posts: 1,166

Original Poster
Rep: Reputation: 45
Could this beused to help create a log file?

And what tty command? I did not know there was even that.
 
Old 10-31-2002, 01:07 PM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
As I understand it you have a shell script that several people may run from different PCs (IP addresses) but may be logged into the Linux box with the same account. You want to track the account name (whoami) and IP address of the PC that launched the script to ultimately start some process? Am i warm?

If I am mostly correct, here is what I described in my post above.

The output of the tty command looks like this:
Code:
# tty
/dev/pts/1
The output of the 'w' command looks like:
Code:
# w
crabboy   pts/1    10.122.2.102:0   24Oct02  0.00s  0.32s  0.05s  w 
crabboy   pts/2    10.122.2.102:0   24Oct02 24:06m  0.16s  0.16s  bash 
crabboy   pts/3    10.122.2.102:0   Tue15   25:25m  0.01s  0.01s  bash
To get what you need, you'd need something like this:
Code:
#!/bin/sh

TTY=`tty | sed 's&/dev/&&'`

USER_IP=`w | grep ${TTY} | awk ' { printf "User [%s] Logged in from [%s]", $1, $2 } '`

echo $USER_IP >> logfile
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding Ip address with Mac address rupeshdwivedi Linux - Networking 6 09-01-2005 07:44 AM
finding process manager.. navaladi Mandriva 3 01-11-2005 03:25 PM
Finding process path praj_linux Solaris / OpenSolaris 5 12-21-2004 10:01 AM
ls -al > log.txt , which process starts first? JrLz Programming 7 12-14-2004 11:25 AM
Finding IP Address [WebCarnage] Linux - Networking 3 03-07-2004 06:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:25 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration