3 # Copyright (C) 2009 Red Hat Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 use Sys::Guestfs::Lib qw(open_guest get_partitions resolve_windows_path
24 inspect_all_partitions inspect_partition
25 inspect_operating_systems mount_operating_system);
29 use File::Temp qw/tempdir/;
31 use Locale::TextDomain 'libguestfs';
37 virt-cat - Display a file in a virtual machine
41 virt-cat [--options] domname file
43 virt-cat [--options] disk.img [disk.img ...] file
47 C<virt-cat> is a command line tool to display the contents of C<file>
48 where C<file> exists in the named virtual machine (or disk image).
50 C<virt-cat> can be used to quickly view a single file. For more
51 complex cases you should look at the L<guestfish(1)> tool.
55 Display C</etc/fstab> file from inside the libvirt VM called
58 virt-cat mydomain /etc/fstab
60 List syslog messages from a VM:
62 virt-cat mydomain /var/log/messages | tail
64 Find out what DHCP IP address a VM acquired:
66 virt-cat mydomain /var/log/messages | grep 'dhclient: bound to' | tail
68 Find out what packages were recently installed:
70 virt-cat mydomain /var/log/yum.log | tail
72 Find out who is logged on inside a virtual machine:
74 virt-cat mydomain /var/run/utmp > /tmp/utmp
79 virt-cat mydomain /var/log/wtmp > /tmp/wtmp
100 Display version number and exit.
106 =item B<--connect URI> | B<-c URI>
108 If using libvirt, connect to the given I<URI>. If omitted, then we
109 connect to the default libvirt hypervisor.
111 If you specify guest block devices directly, then libvirt is not used
118 GetOptions ("help|?" => \$help,
119 "version" => \$version,
120 "connect|c=s" => \$uri,
122 pod2usage (1) if $help;
124 my $g = Sys::Guestfs->new ();
125 my %h = $g->version ();
126 print "$h{major}.$h{minor}.$h{release}$h{extra}\n";
130 pod2usage (__"virt-cat: no image, VM names or filenames to cat given")
133 my $filename = pop @ARGV;
137 $g = open_guest (\@ARGV, address => $uri);
139 $g = open_guest (\@ARGV);
145 # List of possible filesystems.
146 my @partitions = get_partitions ($g);
148 # Now query each one to build up a picture of what's in it.
150 inspect_all_partitions ($g, \@partitions,
151 use_windows_registry => 0);
153 my $oses = inspect_operating_systems ($g, \%fses);
155 my @roots = keys %$oses;
156 die __"no root device found in this operating system image" if @roots == 0;
157 die __"multiboot operating systems are not supported by virt-cat" if @roots > 1;
158 my $root_dev = $roots[0];
160 my $os = $oses->{$root_dev};
161 mount_operating_system ($g, $os);
163 # Allow this to fail in case eg. the file does not exist.
164 # NB: https://bugzilla.redhat.com/show_bug.cgi?id=501888
165 print $g->download($filename, "/dev/stdout");
172 L<Sys::Guestfs::Lib(3)>,
174 L<http://libguestfs.org/>.
178 Richard W.M. Jones L<http://et.redhat.com/~rjones/>
182 Copyright (C) 2009 Red Hat Inc.
184 This program is free software; you can redistribute it and/or modify
185 it under the terms of the GNU General Public License as published by
186 the Free Software Foundation; either version 2 of the License, or
187 (at your option) any later version.
189 This program is distributed in the hope that it will be useful,
190 but WITHOUT ANY WARRANTY; without even the implied warranty of
191 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
192 GNU General Public License for more details.
194 You should have received a copy of the GNU General Public License
195 along with this program; if not, write to the Free Software
196 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.