0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ホストからゲストに、シェルをSCPで送信して実行するantのテンプレート

Posted at

きっかけ

  • VirtualBoxで作業するときゲストでコマンド発行するのがめんどう
  • スナップショットで戻したときに状況に応じてインストールしたい(java7とJava8など)
  • 手順書ではなくシェルで管理したい&別環境でも再利用したい

環境

  • ホスト・・・Windows7
  • ant 1.9.4
  • ゲスト・・・CentOS6

ホストファイル構成

${任意の場所}/setup.bat
${任意の場所}/setup.xml
${任意の場所}/lib/jsch-0.1.52.jar

ビルド実行ファイル

setup.bat
@echo off
call ant make -f ./setup.xml -lib ./lib
rem 「${ANT_HOME}\lib」に直接おいて、build.xmlなら以下のように省略できる
rem call ant make
pause

ビルドファイル

setup.xml
<?xml version="1.0"?>
<project default="make" basedir=".">

  <!-- ホストのIP※ポートフォワードで指定した -->
  <property name="connect.host" value="192.168.11.64" />
  <!-- ゲストのユーザー -->
  <property name="connect.user" value="root" />
  <!-- ゲストのパスワード -->
  <property name="connect.pwd"  value="password" />
  <!-- ゲストのポート※ポートフォワードで指定した -->
  <property name="connect.port" value="22" />

  <target name="make">

    <!-- SCP送信 -->
    <scp todir="${connect.user}:${connect.pwd}@${connect.host}:/root/" port="${connect.port}" trust="true" file="${basedir}/sample.sh" />

    <!-- SSH実行 -->
    <sshexec username="${connect.user}" password="${connect.pwd}" host="${connect.host}" port="${connect.port}" trust="yes" command="chmod +x /root/sample.sh"/>
    <sshexec username="${connect.user}" password="${connect.pwd}" host="${connect.host}" port="${connect.port}" trust="yes" command="/root/sample.sh"/>

  </target>
</project>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?