sshoogr / sshoogr Goto Github PK
View Code? Open in Web Editor NEWA Groovy-based DSL for working with remote SSH servers.
License: Apache License 2.0
A Groovy-based DSL for working with remote SSH servers.
License: Apache License 2.0
There is not way to specify passphrase for the private key. Any chance to implement this? Thanks
Hi guys!
In com.aestasit.ssh.dsl.ScpMethods#upload (ScpMethods.groovy:78) the destination directory is resolved as relative path (using org.apache.commons.io.FilenameUtils#getPath).
In my case this leads to JSCH Error "2: No such file" when supplying an absolute path.
Suggestion: use "getFullPath(dstFile)" to work with the absolute path! Then one should be on the safe side.
Best regards,
Klaus L.
It would be nice to support GStrings in places where Strings are appropriate. For example, this fails:
def site = "www.google.com"
def result = exec(command: "host $site", showOutput: false)
I have to add a .toString()
to the parameter passed to command
I'd be willing to implement this if you'd accept a Pull Request, but would need a few pointers on where to get started.
like this
tunnels([ tunnel(hostname1, remotePort1), tunnel(hostname2, remotePort2) ]) { int[] localPorts ->
// ...
}
If you use outer try block for remoteSession and generate exception from within remoteSession it cause the script hang on exit.
Here is code example:
@Grab(group='com.aestasit.infrastructure.sshoogr', module='sshoogr', version='0.9.16')
import static com.aestasit.ssh.DefaultSsh.*
import java.util.concurrent.TimeoutException
setDefaultKeyFile(new File(System.getenv("HOME")+"/.ssh/id_rsa"))
def user = System.getenv("USER")
try {
remoteSession ("${user}@localhost:22"){
exec "echo Hello world!"
throw new TimeoutException("Bang!")
}
} catch (e) {
println "Warning: ${e.message}"
}
println "Good bye"
The output looks like follows:
>>> Connecting to localhost
> echo Hello world!
Hello world!
Warning: Bang!
Good bye
there is a small typo in README.md
I think the code:
import static com.aestasit.ssh.DefaulSsh.*
should be
import static com.aestasit.ssh.DefaultSsh.*
Hi, is there any further documentation explaining how to set ScpOptions without created a separate engine? I have tried various permutations on (I am new to Groovy, but I did do a bit of research):
remoteSession {
host = args[0]
username = args[1]
scpOptions({
showProgress = false
verbose = false
})
scp "/tmp/foo.zip", '/tmp'
}
however I am still seeing the progress, and when foo.zip is large it is extremely verbose.
Also, the docs say showProgress default is false, which I believe is wrong.
Ideally we would want a DSL along the lines of 'expect', but as a very minimum, the ability to pump stuff through an input stream will allow us to run kinit.
In particular, it took me some time that I have typed commands
rather than command
in the exec arg list.
Hi, I have a groovy program to upload text files to lots of different servers (200-1600 VMs) Using Gpars I am able to spawn many ssh/scp threads to different hosts.
build.gradle dependencies
compile 'org.codehaus.groovy:groovy-all:1.8.4'
compile "com.aestasit.infrastructure.sshoogr:sshoogr:0.9.15"
compile "com.jcraft:jsch:0.1.51"
compile group: 'org.codehaus.gpars', name: 'gpars', version: '1.0.0'
This works in serial with a thread pool of 1, but when I try 10 or 100 concurrent, sshoogr or jsch locks up:
For example where agentList is a ArrayList of 200 Agents (objects with hostname, os type, etc)
and toServer is my target server to direct the agents to (hostname).
public void test()
{
Thread thread = Thread.start()
{
try
{
GParsPool.withPool(10)
{
agentList.eachParallel
{
agent ->
agent.setServerHost(toServer)
}
}
}
catch (Exception e)
{
e.printStackTrace()
}
}
thread.join()
}
and agent.setServerHost(toServer) simply writes a property file and scp it to the host
println "Copying agent.properties to $hostname"
remoteSession("root:perfwire@$hostname:22")
{
scp properties.absolutePath, "/var/tmp/agent.properties"
}
Running this you see my debug output copying agent properties to 10 different hosts, but the sshoogr output
Connecting to the same host 10 times.
If I run it a few times it works and copies a bunch but hangs eventually.
All the hosts are up and I've done this from bash (ssh'ing to all hosts to copy a file).loaded agent list size: 200 Copying agent.properties to dhcp-10-248-8-201.ddns.perf.lab.test.com Copying agent.properties to dhcp-10-248-8-137.ddns.perf.lab.test.com Copying agent.properties to dhcp-10-248-8-100.ddns.perf.lab.test.com Copying agent.properties to dhcp-10-248-8-87.ddns.perf.lab.test.com Copying agent.properties to dhcp-10-248-8-150.ddns.perf.lab.test.com Copying agent.properties to dhcp-10-248-8-125.ddns.perf.lab.test.com Copying agent.properties to dhcp-10-248-8-175.ddns.perf.lab.test.com Copying agent.properties to dhcp-10-248-8-50.ddns.perf.lab.test.com Copying agent.properties to dhcp-10-248-8-75.ddns.perf.lab.test.com Copying agent.properties to dhcp-10-248-8-226.ddns.perf.lab.test.com > Connecting to dhcp-10-248-8-201.ddns.perf.lab.test.com > Connecting to dhcp-10-248-8-201.ddns.perf.lab.test.com > Connecting to dhcp-10-248-8-201.ddns.perf.lab.test.com > Connecting to dhcp-10-248-8-201.ddns.perf.lab.test.com > Connecting to dhcp-10-248-8-201.ddns.perf.lab.test.com > Connecting to dhcp-10-248-8-201.ddns.perf.lab.test.com > Connecting to dhcp-10-248-8-201.ddns.perf.lab.test.com > Connecting to dhcp-10-248-8-201.ddns.perf.lab.test.com > Connecting to dhcp-10-248-8-201.ddns.perf.lab.test.com > Connecting to dhcp-10-248-8-201.ddns.perf.lab.test.com <hang>
One of many threads looks like this. All stuck in socketRead and RUNNABLE.
"ForkJoinPool-1-worker-9" daemon prio=6 tid=0x0000000008a17000 nid=0x3bc runnable [0x0000000009918000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:129) at java.net.SocketInputStream.read(SocketInputStream.java:182) at com.jcraft.jsch.IO.getByte(IO.java:73) at com.jcraft.jsch.Session.connect(Session.java:263) at com.jcraft.jsch.Session.connect(Session.java:183) at com.jcraft.jsch.Session$connect.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112) at com.aestasit.ssh.dsl.SessionDelegate.connect(SessionDelegate.groovy:94) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085) at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:730) at org.codehaus.groovy.runtime.metaclass.OwnedMetaClass.invokeMethod(OwnedMetaClass.java:97) at com.aestasit.ssh.dsl.ScpMethods.invokeMethod(ScpMethods.groovy) at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45) at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:137) at com.aestasit.ssh.dsl.ScpMethods.sftpChannel(ScpMethods.groovy:255) at com.aestasit.ssh.dsl.ScpMethods.this$2$sftpChannel(ScpMethods.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod.invoke(MixinInstanceMetaMethod.java:53) at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:817) at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1134) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1087) at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:730) at org.codehaus.groovy.runtime.metaclass.OwnedMetaClass.invokeMethod(OwnedMetaClass.java:97) at com.aestasit.ssh.dsl.ScpMethods.invokeMethod(ScpMethods.groovy) at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45) at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141) at com.aestasit.ssh.dsl.ScpMethods.scp(ScpMethods.groovy:44) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod.invoke(MixinInstanceMetaMethod.java:53) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085) at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:730) at org.codehaus.groovy.runtime.metaclass.OwnedMetaClass.invokeMethod(OwnedMetaClass.java:97) at com.aestasit.ssh.dsl.ScpMethods.invokeMethod(ScpMethods.groovy) at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45) at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145) at com.aestasit.ssh.dsl.ScpMethods.scp(ScpMethods.groovy:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod.invoke(MixinInstanceMetaMethod.java:53) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:361) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145) at com.tripwire.lab.Agent$_copyAgentProperties_closure4.doCall(Agent.groovy:84) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at com.aestasit.ssh.dsl.SshDslEngine.executeSession(SshDslEngine.groovy:70) at com.aestasit.ssh.dsl.SshDslEngine.this$2$executeSession(SshDslEngine.groovy) at com.aestasit.ssh.dsl.SshDslEngine$this$2$executeSession$5.callCurrent(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149) at com.aestasit.ssh.dsl.SshDslEngine.remoteSession(SshDslEngine.groovy:54) at com.aestasit.ssh.dsl.SshDslEngine$remoteSession$2.callCurrent(Unknown Source) at com.aestasit.ssh.dsl.SshDslEngine.remoteSession(SshDslEngine.groovy:50) at com.aestasit.ssh.dsl.SshDslEngine$remoteSession$0.call(Unknown Source) at com.aestasit.ssh.DefaultSsh.remoteSession(DefaultSsh.groovy:56) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrap.invoke(StaticMetaMethodSite.java:130) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:99) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:53) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:157) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:169) at com.tripwire.lab.Agent.copyAgentProperties(Agent.groovy:81) at com.tripwire.lab.Agent$copyAgentProperties$10.callCurrent(Unknown Source) at com.tripwire.lab.Agent.setServerHost(Agent.groovy:70) at com.tripwire.lab.Agent$setServerHost$4.call(Unknown Source) at com.tripwire.lab.TEAgentManager$_redirect_closure1_closure3_closure4.doCall(TEAgentManager.groovy:42) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at groovyx.gpars.pa.GParsPoolUtilHelper$_eachParallelPA_closure8.doCall(GParsPoolUtilHelper.groovy:190) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) at groovy.lang.Closure.call(Closure.java:411) at org.codehaus.groovy.runtime.ConvertedClosure.invokeCustom(ConvertedClosure.java:51) at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:81) at $Proxy5.op(Unknown Source) at groovyx.gpars.extra166y.AbstractParallelAnyArray$OUPap.leafApply(AbstractParallelAnyArray.java:639) at groovyx.gpars.extra166y.PAS$FJOApply.atLeaf(PAS.java:147) at groovyx.gpars.extra166y.PAS$FJBase.internalCompute(PAS.java:118) at groovyx.gpars.extra166y.PAS$FJBase.compute(PAS.java:106) at jsr166y.RecursiveAction.exec(RecursiveAction.java:148) at jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:305) at jsr166y.ForkJoinWorkerThread.execTask(ForkJoinWorkerThread.java:575) at jsr166y.ForkJoinPool.scan(ForkJoinPool.java:733) at jsr166y.ForkJoinPool.work(ForkJoinPool.java:617) at jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:369)
Hi,
Please provide a way to seed SSH configuration and tell Jsch about host keys. Currently, the following Jsch options are hardcoded[1]:
config.put("StrictHostKeyChecking", "no")
config.put("HashKnownHosts", "yes")
config.put("PreferredAuthentications", "publickey,keyboard-interactive,password")
We would like to be able to enable StrictHostKeyChecking and provide the public key of the target host to Jsch.
Thank you in advance,
In order to create parent directories as needed
Hi, is there any possiblity to setup timeout?
Those scripts are just plain Groovy with few magic imports added
Instead of
assert exec('some command').exitStatus != 0
write
assert exec('some command').failed()
Add ability to enable JSCH debug logging to debug SSH related problems
Hi guys,
probably not so much a code issue, but how do you handle sudo password prompts with sshoogr? I tried fumbling around with sudo -S -p options and then trying to get the password in via stdin, but to no avail. Have you got any working examples? Thanks
It would be great library would be in Maven Central. If you are using a different repository, it should be noted in readme file so people can easily @grab it
I'm not sure if this is the right forum for this, but I did not see any other means of reaching out to the developers of this project.
Recently, I've attempted to use groovy-ssh-dsl to connect to a remote server. I've set up the script to use a particular default host, default user, and default password. However, when I attempt to run the script, it returns a Kerberos prompt
$ groovy SshExample.groovy
07:37:03.799 [main] INFO com.aestasit.ssh.log - >>> Connecting to sptqa-app2.xyz.aert.com
Kerberos username [STAGR005]:
The prompt shows my workstation username. Is there a way to exclude this sort of behavior (i.e., not to use my local workstation username with Kerberos)? I just want it to ssh into the remote box using the default information I've provided within the script
Logging is too verbose (especially for scp). We need to rethink the logging overall and make it more friendly and configurable (both in Groovy and Gradle)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.