Capture IP and command type in linux script

hi guys, is there any way to capture the ip address of users who log-in to linux then capture the command executed together with the time and date?

example output

192.1.1.1 : ls -ltr Aug  6 16:38:40

thanks in advance.

w

Command show who is logged on and what they are doing

You'll need the who command to get information about where they are logged in from. Who will show the host name, and only the IP address if it cannot translate it. Output looks like this:

scooter  :0           Jul 18 10:55 (console)
scooter  pts/0        Jul 18 10:55
scooter  pts/1        Jul 21 22:38 (spot)
scooter  pts/2        Aug  2 14:51
scooter  pts/3        Aug  3 09:57
scooter  pts/4        Aug  6 09:27 (spot)
drr      pts/5        Aug  6 09:30 (192.168.1.7)
scooter  pts/7        Jul 26 23:27 (spot)

The IP/host of that the session is coming from is shown in the last column if it's not local (may differ on non-linux hosts). You'll need to write a script that combines the output from w based on the tty (pts in this case) if you want to display both the "what" and the "where from" information at the same time.

If your script needs to port, be advised that output from who on a FreeBSD system is different -- it has a more consistent output showing all "sources" not just remote ones. Also, the tty listed by w on FreeBSD is a short name p4 rather than ttyp4 where the who command lists the full name.