2016-11-12 10 views
6

私は迷惑メールマシンに単純なコマンドを渡そうとしています。Vagrant ssh - コマンドが動作しない

vagrant ssh -c "mysql -u root -e'CREATE DATABASE testing';" 

dbが作成されません。代わりに、私はちょうどssh経由で迷惑メールマシンに「ログイン」します。

私はまたして試してみた

vagrant ssh -c "touch test.txt" 

実行したときに同じことが起こる:コマンド周り

  • 単一引用符
  • --command代わりの速記-c

を何が起こっているかのアイデア遣り取り?

編集

私は私のスクリプトを配布するつもりだし、ホームステッドで私のスクリプトを統合するために起こっているので、本当に放浪の設定を微調整することはできません。

編集

私はホームステッドのユーザーを使用しているとPWが異なるため。

vagrant ssh -c "mysql -u homestead -psecret -e'CREATE DATABASE testing;'" 

既に送信された回答との混同を避けるため、上記のコードを変更しないでください。

しかし、これは問題を解決しません。上記と同じことが起こっています。

答えて

6

これは動作します

vagrant ssh -- -t 'touch test.txt' 

フラグ-tは、bashが使用する疑似ttyを作成します。 この質問に対する答えのバリエーションはどれですか。ここでは詳細に説明されて

Running remote commands after vagrant ssh

https://unix.stackexchange.com/questions/119894/single-command-to-login-to-ssh-and-run-program/119899#119899

+1

はい!これはうまくいった。ありがとう、キース。非常に高く評価 –

0

あなたのブートストラップファイルにそのコマンドを追加してみてください、その後

vagrant provision 

を使用することができます。

例VargantはそれであなたのコマンドでPostgresデータベースを作成します

# -*- mode: ruby -*- 
# vi: set ft=ruby : 

Vagrant.configure(2) do |config| 
    config.vm.box = "ubuntu/trusty64" 

    config.vm.network "forwarded_port", guest: 8080, host: 8080 

    config.vm.provision :shell, path: "bootstrap.sh" 

    config.vm.provider "virtualbox" do |v| 
     v.memory = 1024 
    end 

    config.vm.synced_folder "./", "/vagrant", id: "vagrant-root", 
     owner: "vagrant", 
     group: "www-data", 
     mount_options: ["dmode=777,fmode=777"] 

end 

例bootstrap.shファイル。適切なmysqlパッケージがインストールされていることを確認する必要があります。

#!/usr/bin/env bash 

add-apt-repository ppa:ondrej/php5-5.6 
apt-add-repository ppa:chris-lea/redis-server 

apt-get update 

apt-get install -y --force-yes python-software-properties 

apt-get install -y --force-yes postgresql postgresql-contrib 

apt-get install -y --force-yes redis-server 
apt-get install -y --force-yes apache2 
apt-get install -y --force-yes php5 
apt-get install -y --force-yes php5-imagick 
apt-get install -y --force-yes php5-redis 
apt-get install -y --force-yes php5-mcrypt 
apt-get install -y --force-yes phppgadmin 
apt-get install -y --force-yes php5-gd 
apt-get install -y --force-yes php5-intl 
apt-get install -y --force-yes php5-sqlite 
apt-get install -y --force-yes php5-curl 
apt-get install -y --force-yes git 

if ! [ -L /var/www ]; then 
    rm -rf /var/www 
    mkdir /var/www 
    ln -fs /vagrant /var/www/vagrant-referron-com 
    # 
    sed -i "s#DocumentRoot /var/www/html#DocumentRoot /var/www#g" /etc/apache2/sites-available/000-default.conf 

fi 
sed -i "s#AllowOverride None#AllowOverride All#g" /etc/apache2/sites-available/000-default.conf 
sed -i "s#AllowOverride None#AllowOverride All#g" /etc/apache2/apache2.conf 


# copy the phppgadmin configuration 
cp -f /vagrant/development/postgres/phppgadmin /etc/apache2/conf.d/ 
cp -f /vagrant/development/postgres/phppgadmin.conf /etc/apache2/conf-enabled/ 
cp -f /vagrant/development/postgres/config.inc.php /etc/phppgadmin/ 

# create the postgres database and user 
sudo -u postgres createdb sometestdatabase 
sudo -u postgres psql -U postgres -d postgres -c "alter user postgres with password 'postgres';" 

# calling mysql to create your testing database. 
sudo mysql -u root -e 'CREATE DATABASE testing ;' 


# enable server to listen to port 8080 
cp -f /vagrant/development/ports.conf /etc/apache2/ 

# install the other apache modules 
a2enmod rewrite 
php5enmod mcrypt 


apachectl restart 
+0

おかげで、このために、私は私のスクリプトを配布することを計画してvagrantfilesいじりすることはできません。私は特にホームステッドと統合しようとしています。しかし、ありがとう。申し訳ありませんが、私の間違いを指定していないため –

0

が直接浮浪者の代わりにsshを使用してみてください:

ssh vagrant -c 'your command' 

あなたはおそらくあなたの中に流行病院のホストを定義する必要があります~/.ssh/config

Host vagrant 
    HostName 127.0.0.1 
    User vagrant 
    Port 2222 
    IdentityFile ~/.vagrant.d/insecure_private_key 
    UserKnownHostsFile /dev/null 
    StrictHostKeyChecking no 
    PasswordAuthentication no 
    IdentitiesOnly yes 
    LogLevel FATAL 
    ForwardAgent yes 
関連する問題