`multipass exec` command


The multipass exec command executes the given commands inside the instance. The first argument is the instance to run the commands on, -- optionally separates the multipass options from the rest - the command to run itself:

$ multipass exec primary -- uname -r

You can pipe standard input and output to/from the command:

$ multipass exec primary -- lsb_release -a | grep ^Codename:
No LSB modules are available.
Codename:       bionic

The full multipass help exec output explains the available options:

$ multipass help exec
Usage: multipass exec [options] <name> [--] <command>
Run a command on an instance

  -h, --help     Display this help
  -v, --verbose  Increase logging verbosity, repeat up to three times for more

  name           Name of instance to execute the command on
  command        Command to execute on the instance

The -- separator is required if you want to pass options to the command being run.

1 Like

I have a lot of scripts that I need to pass into a multipass instance, on launch I am passing a YAML file with a cloud config using write_files. I need to keep those files up to date so I am trying to run a command that will write those files using exec.

Something along the lines of this:

multipass exec name -- sudo echo content > /path/to/file

What would be the best approach to accomplishing this?