Skip to content

Instantly share code, notes, and snippets.

@taisukeoe
Last active December 21, 2015 17:49
Show Gist options
  • Save taisukeoe/6343272 to your computer and use it in GitHub Desktop.
Save taisukeoe/6343272 to your computer and use it in GitHub Desktop.
awscala.ec2.Instanceに、単純なssh/scpをscala-ssh非依存で実行させてみるてすつ。
def process(command: String, keyPairFile: File, sshOption: String = "-o StrictHostKeyChecking=no -t -t"): Either[String, String] = {
import sys.process._
try {
Right(s"echo ${command}" #&& "echo exit" #> s"ssh ${sshOption} -i ${keyPairFile.getAbsolutePath} ec2-user@${publicDN}" !!)
} catch { case e: Exception => Left(e.toString) }
}
def scp(file: File, keyPairFile: File, scpOption: String = "-o StrictHostKeyChecking=no"): Either[String, String] = {
import sys.process._
try {
Right(s"scp -P 22 ${scpOption} -i ${keyPairFile.getAbsolutePath} ${file.getAbsolutePath} ec2-user@${publicDN}:${file.getName}" !!)
} catch { case e: Exception => Left(e.toString) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment