简体   繁体   中英

How to run bash script in vagrant from under sudo su -?

I get into the vagrant shell and then go under sudo su - in my project. Next I have to go to the folder with the command cd /var/www/html and execute the command to generate documents, let it be generate_document. But the problem is that if I write a bash script on all these actions, I stop in the vagrant shell

I tried the command and a few lines in the file, but not one action has helped me.

How can I write a bash script that:

  • comes into vagrant with the command 'vagrant ssh my_crm'
  • performs input under 'sudo su -'
  • goes into the folder 'cd /var/www/html/'
  • executes 'generate_document'
#!/usr/bin/env bash

cd ~/Desktop/Work/arteccrm/vagrant

first variant
vagrant ssh my_crm -c " sudo su -; cd /var/www/html/; generate_document"

another variant
sudo-s -- "vagrant ssh my_crm; cd /var/www/html/; generate_document"

another variant
vagrant ssh my_crm -c 'sudo su -' && ssh my_crm -c ' cd /var/www/html/; generate_document'

another variant
vagrant ssh my_crm -c 'sudo su - && cd /var/www/html/ && generate_document'

another variant
vagrant ssh my_crm -c 'sudo su -'
vagrant ssh my_crm -c 'cd /var/www/html/'
vagrant ssh my_crm -c 'generate_document'

another variant
vagrant ssh crm -c 'cd /var/www/html/'
vagrant ssh crm -c 'cd /var/www/html/'
cd /var/www/html/ && generate_document

I found a solution my problem:

vagrant ssh crm -c 'sudo sh -c "cd /var/www/html/; generate_document"'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM