Tag Archives: who

libguestfs: How to find out who is logged in to a virtual machine

This neat trick (with libguestfs 1.0.61) lets you see who is logged in to a Linux virtual machine:

# virt-cat CentOS5x32 /var/run/utmp > /tmp/utmp
# who /tmp/utmp
rjones   :0           2009-07-09 11:00
rjones   pts/1        2009-07-09 11:00 (:0.0)

or to find out who was logged in:

# virt-cat CentOS5x32 /var/log/wtmp > /tmp/wtmp
# last -f /tmp/wtmp
rjones   pts/2        192.168.122.1    Tue Jul 14 14:22 - 15:28  (01:05)    
rjones   pts/2        192.168.122.1    Tue Jul 14 14:18 - 14:22  (00:03)    
rjones   pts/2        192.168.122.1    Fri Jul 10 12:28 - 12:44  (00:16)    
rjones   pts/2        192.168.122.1    Thu Jul  9 11:00 - 11:16  (00:15)    
rjones   pts/1        :0.0             Thu Jul  9 11:00    gone - no logout 
rjones   :0                            Thu Jul  9 11:00    gone - no logout 

virt-cat is a new tool we wrote, which doesn’t particularly do anything more than the existing guestfish ‘cat’ command, but is wrapped up in a way that makes it a bit easier to use.

Leave a comment

Filed under Uncategorized