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:
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