[SOLVED] Using gb.util prompt/expect with ssh client
Posted
#1
(In Topic #687)
Trainee
I would like to know whether anyone had success with connecting to ssh server (or telnet) using expect/prompt from Process class that is in gb.util component (beginning with Gambas 3.15)? I myself tried but with no success. Any working example would be appriciated!
Thanks in advance!
Posted
Guru

This is a puzzle. Two of us have been trying to get this to work for the last 3 hours with very little progress. We haven't given up just yet, so watch this space. Can you tell us what you are trying to achieve, there maybe another way to do this?
Posted
Trainee
I would like to develop an application which would periodically save configurations of active network devices like switches, routers, etc. I could implement that using python and qt (in python there are different libraries like paramiko) but it is much more easier to develop GUI applications in Gambas than in any other language.
Looking forward to your help!
Posted
Trainee
It works great for me (written in java and php) but it is no longer supported and i would like to expand the functionality it gives in my application.
Posted
Guru

Here is a Gambas program in which I created some simple Python, ran the Python and displayed the result in Gambas.
Posted
Guru

I read in the wiki the bit from Process.Expect()
/comp/gb.util/process/expect - Gambas Documentation
Read some bit (cannot remember where) that said no more but had (Think ssh/ssl) appended to it.
but it had no further explanation/example.
I'd try the mailing list and see if whoever wrote the command has an explanation.
Does this not help?…
Code (gambas)
- ' Handle the message emitted when the server is unknown
- hProcess.Expect("(yes/no*)?", "yes")
- ' Any emitted string ending with a colon is supposed to be the password prompt
- hProcess.Expect(":", sPassword)
- ' Wait for the process to terminate
- hProcess.Wait
Posted
Trainee
cogier said
This is going over my head. However, if you can do all this in Java and PHP then why not use that code and pull it in to Gambas to display.
Here is a Gambas program in which I created some simple Python, ran the Python and displayed the result in Gambas.
TestNew-0.0.11.tar.gz
Hi!
I didn't say that I know Java or Php. I meant that CBackup project is written in those languages. I gave you the link to the project as an example what I would like to implement. And I would like to write the whole code in pure gambas. According to Gambas wiki there is an appropriate functionality but, unfortunately, it doesn't work as I expect it to.
Posted
Trainee
BruceSteers said
Maybe ask on the gambas mailing list?
I read in the wiki the bit from Process.Expect()
/comp/gb.util/process/expect - Gambas Documentation
Read some bit (cannot remember where) that said no more but had (Think ssh/ssl) appended to it.
but it had no further explanation/example.
I'd try the mailing list and see if whoever wrote the command has an explanation.
Does this not help?…Code (gambas)
' Handle the message emitted when the server is unknown hProcess.Expect("(yes/no*)?", "yes") ' Any emitted string ending with a colon is supposed to be the password prompt hProcess.Expect(":", sPassword) ' Wait for the process to terminate hProcess.Wait
I already read everything related to expect/prompt on Gambas wiki but that doesn't work when it comes to ssh and/or telnet. I asked the same question in Gambas official IRC channel. No answer. I will try mailing list as you advised.
Posted
Trainee
Here is a working example of ssh connection from Gambas project:
Code (gambas)
- ' Gambas module file
- "cd /",
- "df -h",
- "exit"]
- ' if you change this to use a shell it does not work at all
- 'MyProcess = Shell "ssh gshdemo@localhost" For Input Output As "TheProcess"
- Print "set prompt"
- myprocess.expect(":", "password")
- While myprocess.Running
- myprocess.expect("*:?$") ' wait for prompt
- myprocess.expect("*closed.") ' wait for prompt
- Inc CurrentCmd
- GotPrompt = False
- myprocess.Kill
- Print "Got prompt", thePrompt, theanswer
- Case "*:"
- logonComplete = True
- Case "*:?$"
- GotPrompt = True
- Case "*closed."
- ConnectionOpen = False
- buffer &= Read #MyProcess, readlen
- Print buffer
- 'Flush
1 guest and 0 members have just viewed this.



