|
Project Information
Featured
Downloads
Links
|
JASSH : High level scala SSH API for easy and fast operations on remote servers.This API is JSCH based. Interfaces are stable. A standalone packaging, "jassh.jar", is provided, for quick console or scripting usage. It embeds all dependencies, and comes with all scala libraries. Otherwise for library usage, just add the dependency and the repository to your sbt configuration file (build.sbt). Just run "java -jar jassh.jar -usejavacp" to start the console, see a usage example below. JAnalyse software maven repository : http://www.janalyse.fr/repository/ Scala docs : http://www.janalyse.fr/scaladocs/janalyse-ssh (work in progress...) Current release : 0.7.4 (for scala 2.9.1, 2.9.2) Declare dependency in SBT as follow : libraryDependencies += "fr.janalyse" %% "janalyse-ssh" % "0.7.4" % "compile" Add JAnalyse repository in SBT as follow : resolvers += "JAnalyse Repository" at "http://www.janalyse.fr/repository/" hello world script : It requires a local user named "test" with password "testtest", remember that you can remove the password, if your public key has been added in authorized_keys file of the test user. #!/bin/sh
exec java -jar jassh.jar -nocompdaemon -usejavacp -savecompiled "$0" "$@"
!#
jassh.SSH.shell("localhost", "test", "testtest") { sh =>
print(sh.execute("""echo "Hello World from `hostname`" """))
}console usage example : $ java -jar jassh.jar -usejavacp
scala> import jassh._
import jassh._
scala> val found = SSH.once("localhost", "test") {_ executeAndTrimSplit "find /usr/share -name '*.jpg'"}
found: Array[java.lang.String] = Array(/usr/share/gtkhtml-3.14/icons/midnight-stars.jpg, ...
scala> remote vmstat script : #!/bin/sh
exec java -jar jassh.jar -nocompdaemon -usejavacp -savecompiled "$0" "$@"
!#
jassh.SSH.once("localhost", "test", password="testtest") {
_.run("vmstat 1 10", (l)=> l foreach {println(_)}).waitForEnd
}Usages example : test("Usage case example - for tutorial") {
import fr.janalyse.ssh.SSH
SSH.once(host = "localhost", username = "test") { ssh =>
val uname = ssh executeAndTrim "uname -a"
val fsstatus = ssh execute "df -m"
val fmax = ssh get "/proc/sys/fs/file-max"
ssh.shell { sh => // For higher performances
val hostname = sh.executeAndTrim("hostname")
val files = sh.execute("find /usr/lib/")
}
ssh.ftp { ftp => // For higher performances
val cpuinfo = ftp.get("/proc/cpuinfo")
val meminfo = ftp.get("/proc/meminfo")
}
// output streaming
def receiver(data:Option[String]) {data foreach {println(_)}}
val executor = ssh.run("vmstat 1 3", receiver)
executor.waitForEnd
}
}
test("Simultaenous SSH operations") {
val started = System.currentTimeMillis()
val h="127.0.0.1"
val cnxinfos = List(h,h,h,h,h) map {h=> SSHOptions(host=h, username="test")}
val sshs = cnxinfos.par map {SSH(_)}
val unames = sshs map {_ execute "date; sleep 5"}
info(unames.mkString("----"))
(System.currentTimeMillis() - started) should be < (6000L) //(and not 5s * 5 = 25s)
}
test("Simplified persistent ssh shell usage") {
SSH.shell(host = "localhost", username = "test") { sh =>
sh.execute("ls")
sh.execute("uname")
}
}
test("Simplified persistent ssh shell and ftp usage") {
SSH.shellAndFtp(host = "localhost", username = "test") { (sh, ftp) =>
sh.execute("ls")
sh.execute("uname")
ftp.get("/proc/stat")
ftp.get("/proc/vmstat")
}
}
Tests results on a AMD Phenom(tm) II X6 1090T, 3200Mhz, up to 500 commands per seconds ! [info] SSHAPITest: [info] - One line exec with automatic resource close [info] - Execution & file transferts within the same ssh session (autoclose) [info] - shell coherency check [info] - shell coherency check with long command lines (in //) [info] - SSHShell : Bad performances obtained without persistent schell ssh channel (autoclose) [info] + Performance using shell without channel persistency : 93,0 cmd/s [info] - SSHShell : Best performance is achieved with mutiple command within the same shell channel (autoclose) [info] + Performance using with channel persistency : 506,1 cmd/s [info] - SSHExec : performances obtained using exec ssh channel (no persistency) [info] + Performance using exec ssh channel (no persistency) : 93,4 cmd/s [info] - Start a remote process in background [info] + 0 : procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- [info] + 1 : r b swpd free buff cache si so bi bo in cs us sy id wa [info] + 2 : 0 0 0 12831388 155896 600696 0 0 7 11 183 258 3 0 97 0 [info] + 3 : 0 0 0 12831428 155896 600692 0 0 0 12 900 744 0 0 100 0 [info] + 4 : 0 0 0 12831328 155896 600700 0 0 0 0 1058 1341 0 0 99 0 [info] + 5 : 0 0 0 12831312 155896 600700 0 0 0 0 1365 1809 1 0 99 0 [info] + 6 : 0 0 0 12831328 155912 600688 0 0 0 188 681 635 0 0 98 2 [info] - Usage case example - for tutorial [info] - Simultaenous SSH operations [info] + Sun Apr 1 14:45:25 CEST 2012----Sun Apr 1 14:45:25 CEST 2012----Sun Apr 1 14:45:25 CEST 2012----Sun Apr 1 14:45:25 CEST 2012----Sun Apr 1 14:45:25 CEST 2012 [info] - Simplified persistent ssh shell usage [info] - Simplified persistent ssh shell and ftp usage [info] - simplified usage with sshOptions as Option [info] Passed: : Total 13, Failed 0, Errors 0, Passed 13, Skipped 0 [success] Total time: 28 s, completed 1 avr. 2012 14:45:30 |