2017-12-18 14 views
0

リモートマシンにスクリプトをデプロイして自動的に実行したい。sbtスクリプトでリモートsshコマンドを実行するには?

しかし、リモートコマンドをどのように発行できるかわかりません。

私はいくつかのことを試しましたが、プラグインは動作しませんでした。

これを行う方法はありますか?ここで

val deployAndRunTask = TaskKey[Unit]("deploy-run", "Deploy and run application.") 

deployAndRunTask := { 

    // Deploy .jar file 
    val _ = deployTask.value 

    println("Running the script ..") 

} 

答えて

0

はあなたのSBTプロジェクトの最上位ディレクトリにtest.sbtに保存することができます作業例、です。 shellRunメソッドは任意のコマンドを実行します。私はshellRunを使ってsshを実行し、ローカルマシンに接続し、私のホームディレクトリにファイルをリストアップします。

import scala.sys.process.Process 

val deployAndRunTask = TaskKey[Unit]("deploy-and-run-task", "Short example") 

deployAndRunTask := { 
    def shellRun(command: String*) = Process(command.toSeq).!!.trim 

    val result = shellRun("/usr/bin/ssh", "localhost", "ls") 
    println(result) 
} 

次のように入力して実行して:

sbt deployAndRunTask 
関連する問題