running a script.sh on guest os

145 views
Skip to first unread message

saurav savarn

unread,
Sep 27, 2020, 12:25:31 PM9/27/20
to Vagrant
How to execute a script containing multiple command on guest machine

NOTE: i have already defined in my Vagrant File as

config.vm.synced_folder ".", "/home/vagrant/Downloads/"


As per website, i have added below line into providers section of VagrantFile which i need to execute once the guestOS is up and running as:

config.vm.provider "virtualbox" do |vb|

     vb.memory = "2048"

     vb.name = "Cassandra-4.0-Vagrant"

     config.trigger.after :up do |trigger|

        trigger.name = "execute script"

        trigger.info = "running multiple commands within the script"

        trigger.run = {path: "sh launch-cassandra.sh" }

     end

  end


Now Output i am receiving is :

There are errors in the configuration of this machine. Please fix

the following errors and try again:


trigger:

* `path` for shell provisioner does not exist on the host system: 


Also since this file which i am trying to execute on Guest OS, exists in the Download section with the path as /home/vagrant/Downloads (which i have already mentioned in the start), after login into guest os using vagrant ssh command and executing directly , it is running successfully.


Kindly provide me the solution to execute this scripts while executing command vagrant reload





dnmo...@gmail.com

unread,
Sep 29, 2020, 9:32:34 AM9/29/20
to Vagrant
So the shell command you are using e.g. sh is a convenience alias (usually located and sourced in/from your .bashrc file) when you are actually logged into a machine (called interactive mode/shell). Typically when you are running a script in this fashion you are using a non-interactive shell meaning the convenience aliases are not available to you (.bashrc file is not sourced). As a result you would need to explicitly target the shell command directly like /usr/bin/sh or /bin/bash etc. 

dragon788

unread,
Sep 30, 2020, 8:33:56 AM9/30/20
to Vagrant
You were close dnmorgan, but using `/bin/sh` as `sh` isn't an alias, it is using the PATH to find an executable without requiring the user to supply the full path.

The issue in this case is that instead of supplying a path he's supplying a command. The trigger.run may already be assuming it is a script, but it won't immediately start in the downloads folder just because it was mapped. The path should be `/home/vagrant/Downloads/launch-cassandra.sh`.
Reply all
Reply to author
Forward
0 new messages