[racket] looking for a simple ssh library.

130 views
Skip to first unread message

jo

unread,
Feb 28, 2013, 9:33:30 AM2/28/13
to us...@racket-lang.org
Hi

I am looking for a simple ssh library a la net::snmp. The remote node does not have racket installed. I want to send and receive commands to the device.

Thanks
J.

Michael Wilber

unread,
Feb 28, 2013, 10:26:48 AM2/28/13
to jo, us...@racket-lang.org
I know it's a hack but for my needs, I just spawn a synchronous ssh
process, like this:

(define (get-remote-file file)
(define success? #t)
(define remote-bytes
(with-output-to-bytes
(λ() (set! success?
(system (format "ssh machinename cat ~a" file))))))
(and success? remote-bytes))

> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users

____________________
Racket Users list:
http://lists.racket-lang.org/users

Tony Garnock-Jones

unread,
Feb 28, 2013, 10:44:36 AM2/28/13
to jo, us...@racket-lang.org
I am working on a project that includes writing an implementation of
SSHv2. At the moment it's not quite usable as a client: I have yet to
implement the auth subprotocol, for one.

If Michael Wilber's suggestion of just using (system) doesn't work for
you, let me know and I'll see what I can do about polishing it up for
release.

(Incidentally, I've used (system) to launch ssh to start remote commands
before: the only sticking point for me was I needed to use the "-tt" flag:

(process (format "ssh -tt ~a '~a'" machine-name command))

... because I wanted my long-running job to be killed when the SSH
connection closed, rather than living on afterward; giving it a
controlling TTY is important in that case.)

Regards,
Tony

Eli Barzilay

unread,
Feb 28, 2013, 10:56:36 AM2/28/13
to Michael Wilber, jo, us...@racket-lang.org
30 minutes ago, Michael Wilber wrote:
> I know it's a hack but for my needs, I just spawn a synchronous ssh
> process, like this:
>
> (define (get-remote-file file)
> (define success? #t)
> (define remote-bytes
> (with-output-to-bytes
> (λ() (set! success?
> (system (format "ssh machinename cat ~a" file))))))
> (and success? remote-bytes))

(`system' should almost never be used in public code... Imagine
someone using the above code and dealing with the consequences of file
names like "foo; rm -rf ~".)

--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!

Michael Wilber

unread,
Feb 28, 2013, 1:22:12 PM2/28/13
to Eli Barzilay, jo, us...@racket-lang.org
Oh geez, that's a very good point. Thanks for catching that before
an attacker does, Eli.

David Vanderson

unread,
Feb 28, 2013, 1:30:59 PM2/28/13
to Eli Barzilay, jo, us...@racket-lang.org
Eli,

What's the solution here, use 'subprocess' or 'system*' to prevent shell
execution?

Thanks,
Dave

On 02/28/2013 07:56 AM, Eli Barzilay wrote:
> (`system' should almost never be used in public code... Imagine
> someone using the above code and dealing with the consequences of file
> names like "foo; rm -rf ~".)

jo

unread,
Feb 28, 2013, 5:09:37 PM2/28/13
to Tony Garnock-Jones, us...@racket-lang.org

Indeed the need is more complicated, the code needs to talk to an agent at the ssh side whose behaviour can be unpredictable. So some kind of bidirectional pipe to ssh is needed to achieve this, it is more than just launching ssh commands. I have just now been prototyping with paramiko in python as well and discovered I also need a kind of unbuffered stream (non blocking io).

Thanks
J.


From: Tony Garnock-Jones <to...@ccs.neu.edu>
To: jo <etao...@yahoo.com>
Cc: "us...@racket-lang.org" <us...@racket-lang.org>
Sent: Thursday, February 28, 2013 4:44 PM
Subject: Re: [racket] looking for a simple ssh library.

Tony Garnock-Jones

unread,
Feb 28, 2013, 5:20:34 PM2/28/13
to jo, us...@racket-lang.org
On 2013-02-28 5:09 PM, jo wrote:
> bidirectional pipe to ssh is needed to achieve this, it is more than
> just launching ssh commands.

You might have some luck using (process) from racket/system to get input
and output ports to the remote process, combined with using (sync) to
get the nonblocking behaviour.

For example:

(match-define (list from-remote
to-remote
pid
error-from-remote
control-remote)
(process (string-append "ssh -tt "machine" '"command"'")))

gives you stdin, stdout and stderr ports for communicating with the
remote process.

jo

unread,
Mar 12, 2013, 4:19:07 AM3/12/13
to us...@racket-lang.org
program below does direct browser to the site requested but at same time also gives an error.
How can I work around this error ?  Used this with chrome as default browser. Is there a way to select different browsers without having to change default browser setting?

#lang racket

(require (planet esilkensen/yaml:2:=1))
(require (planet dyoo/browser-evaluate:1:0))
(require (planet gh/sha:1:1))        

(define (go-site url)
  (let* ( (code (format  " window.location.href ='~a'; $SUCC(1);" url )) )
     (write (format  "exec ~a" code ))
     (js-evaluate code ) ))

;
(go-site "https://www.coursera.org/")

fails with

(evaluated "" "1" 1 "Chrome 25/Windows")
. . C:\Program Files (x86)\Racket\collects\web-server\private\dispatch-server-unit.rkt:96:6: tcp-write: error writing
  system error: Unknown error; errno=10053
>

Jay McCarthy

unread,
Mar 14, 2013, 1:22:23 PM3/14/13
to jo, us...@racket-lang.org
I'm sorry Jo, I don't fully understand your question. It seems to be
about the OS's default browser setting? Or is it the DrRacket browser
setting (which can be changed in the preferences)? The error message
you see is innocuous and was removed from Racket a while ago... what
version are you using?

Jay
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>



--
Jay McCarthy <j...@cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93
Reply all
Reply to author
Forward
0 new messages