" -h|--cmd-help cmd Display detailed help on 'cmd'\n"
" -a|--add image Add image\n"
" -D|--no-dest-paths Don't tab-complete paths from guest fs\n"
+ " -f|--file file Read commands from file\n"
" -m|--mount dev[:mnt] Mount dev on mnt (if omitted, /)\n"
" -n|--no-sync Don't autosync\n"
" -r|--ro Mount read-only\n"
int
main (int argc, char *argv[])
{
- static const char *options = "a:h::m:nrv?V";
+ static const char *options = "a:f:h::m:nrv?V";
static struct option long_options[] = {
{ "add", 1, 0, 'a' },
{ "cmd-help", 2, 0, 'h' },
+ { "file", 1, 0, 'f' },
{ "help", 0, 0, '?' },
{ "mount", 1, 0, 'm' },
{ "no-dest-paths", 0, 0, 'D' },
struct drv *drv;
struct mp *mps = NULL;
struct mp *mp;
- char *p;
+ char *p, *file = NULL;
int c;
initialize_readline ();
complete_dest_paths = 0;
break;
+ case 'f':
+ if (file) {
+ fprintf (stderr, _("guestfish: only one -f parameter can be given\n"));
+ exit (1);
+ }
+ file = optarg;
+ break;
+
case 'h':
if (optarg)
display_command (optarg);
mount_mps (mps);
}
+ /* -f (file) parameter? */
+ if (file) {
+ close (0);
+ if (open (file, O_RDONLY) == -1) {
+ perror (file);
+ exit (1);
+ }
+ }
+
/* Interactive, shell script, or command(s) on the command line? */
if (optind >= argc) {
if (isatty (0))
guestfish --add disk.img \
--mount /dev/VolGroup00/LogVol00 \
--mount /dev/sda1:/boot \
- rm /boot/grub/menu.lst : \
- sync : exit
+ rm /boot/grub/menu.lst
=head2 As an interactive shell
><fs> help
+=head2 As a script interpreter
+
+ #!/usr/bin/guestfish -f
+ alloc /tmp/output.img 10M
+ run
+ sfdisk /dev/sda 0 0 0 ,
+ mkfs ext2 /dev/sda1
+
=head1 DESCRIPTION
Guestfish is a shell and command-line tool for examining and modifying
Add a block device or virtual machine image to the shell.
+=item B<-f file> | B<--file file>
+
+Read commands from C<file>. To write pure guestfish
+scripts, use:
+
+ #!/usr/bin/guestfish -f
+
=item B<-m dev[:mountpoint]> | B<--mount dev[:mountpoint]>
Mount the named partition or logical volume on the given mountpoint.