Visit The New, Modern Unix Linux Community

Capture IP and command type in linux script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Capture IP and command type in linux script
# 1  
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

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

thanks in advance.
# 2  

Command show who is logged on and what they are doing
# 3  
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 (
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.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #612
Difficulty: Medium
In Python, they are five numeric types - integers, long integers, floating point, infinite, and complex numbers.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need command to capture word from shell script and send email

Hello Experts, Greeting to all of you. I have a requirement, that we have a shell script that check the status of server and server status shows as Enterprise Server - Running Admin Server - Shutdown Requirement is like whenever the output shows shutdown it should... (2 Replies)
Discussion started by: aks_1902
2 Replies

2. Shell Programming and Scripting

Capture the data in Linux .While doing load test.

Hi All, I am trying to capture the data in linux .While doing load test. is there's any sample script please help me. Linux test4 2.6.18-308.8.1.el5 #1 SMP Fri May 4 16:43:02 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux Thanks, (5 Replies)
Discussion started by: sam1226
5 Replies

3. Solaris

How to capture Output of truus command

Hi I want to check if some process is sleeping. I can see that in truss -p <pid> I want to capture output and check that output if proces sis sleeping. Please suggest way to capture output of truss command or other way to check if process is sleeping (1 Reply)
Discussion started by: ankush_mehra
1 Replies

4. Linux

How do I capture responses from the chat command?

Unfortunately googling the word 'chat' gives you zebedee billion responses that relate to everything and few of them refer to the linux chat command. I've read the man page and found a couple of examples but can't see how to do this. I want to query the modem for it's manufacturer, product id... (8 Replies)
Discussion started by: Bashingaway
8 Replies

5. UNIX for Dummies Questions & Answers

Doing a capture while another command is executing?

Basically what i'm trying to do is execute an update command and at the same time have the system do a TCPdump to file for that update traffic. So I would like to connect the two commands so that the tcpdump terminates automatically when the update finishes/fails/whatever. Right now I have... (0 Replies)
Discussion started by: MrEddy
0 Replies

6. Shell Programming and Scripting

Enter the command to capture output--help

&& echo "PLEASE enter the command to capture output" || echo "Processing your command manual" x=$# echo $x while do while man $@ | read -r line do >$@.txt ... (1 Reply)
Discussion started by: rrd1986
1 Replies

7. Shell Programming and Scripting

Trouble with tee command to capture script outputs

function GetInput { print -n "Input" read input export INPUT=$input } export COMMAND="GetInput" $COMMAND echo "$INPUT" $COMMAND | tee -a Log.log echo "$INPUT" The first one without "tee" works fine. echo "$INPUT" displays the values I type in for input. The second... (5 Replies)
Discussion started by: muthubharadwaj
5 Replies

8. Cybersecurity

What command or script to capture a system snapshot?

Some background on what I am trying to accomplish - Accreditation/Certification for DoD (Unix/Linux) system: I am trying to improve the process for capturing key system information in preparation for performing a formal security review of a Unix or Linux system. This is in addition to the SRR... (1 Reply)
Discussion started by: SecureMe
1 Replies

9. Linux

how to identify the raid type on Linux?

Hi any idea on why I am getting this? /sbin/mdadm --detail /dev/md0 mdadm: md device /dev/md0 does not appear to be active. thanks. (2 Replies)
Discussion started by: melanie_pfefer
2 Replies

10. Shell Programming and Scripting

Capture entire line in ps command

I need to determine what processes are running at certain times of the day. I have a script that issues the /usr/ucb/ps aux command and captures it to a file. I want to see the cpu usage and memory usage. This command lops off the end of the of the display line so I can't see the entire... (2 Replies)
Discussion started by: MizzGail
2 Replies

Featured Tech Videos