Interaction With Command Shell

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Interaction With Command Shell

Nigel Verity
Hi

I would welcome some advice about interacting with the Linux command shell from within a Gambas application.

The requirement is to create a connection with a remote server using SSHFS. The general syntax for this command is:

sshfs username@remote-server:/foldername /local-mount-folder

There is no option in the SSHFS command to include the user's password on the remote server. When running from a command prompt, once the sshfs command is accepted you are then prompted to enter the password.

Is there any way, after executing the SSHFS command (using SHELL, presumably) to monitor for the password prompt and then send the password to the command shell?

My aim is to create a dialog in which the user provides the server name, username and password and have Gambas do the rest to create the SSHFS connection.

Thanks

Nige      
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: Interaction With Command Shell

Tobias Boege-2
On Mon, 16 Mar 2015, Nigel Verity wrote:

> Hi
>
> I would welcome some advice about interacting with the Linux command shell from within a Gambas application.
>
> The requirement is to create a connection with a remote server using SSHFS. The general syntax for this command is:
>
> sshfs username@remote-server:/foldername /local-mount-folder
>
> There is no option in the SSHFS command to include the user's password on the remote server. When running from a command prompt, once the sshfs command is accepted you are then prompted to enter the password.
>
> Is there any way, after executing the SSHFS command (using SHELL, presumably) to monitor for the password prompt and then send the password to the command shell?
>
> My aim is to create a dialog in which the user provides the server name, username and password and have Gambas do the rest to create the SSHFS connection.
>

I have once tried that, specifically with sshfs, too, and failed miserably.
Your zeroth approximation should be to factor out Gambas and write a shell
script which can pass the password to sshfs. If you've got that, you almost
have the solution in Gambas.

There is a program "expect" which was designed for specifically the purpose
of waiting on a program's output for a specific pattern and then sending a
given string to its input (i.e. to automate interactive programs). But it
seems sshfs is putting extra effort into preventing this automation.

I ended up creating a private/public key pair and have the server work with
that so that I can login using these keys[0]. Maybe this is an option for
you, too?

If you can trick sshfs into being automated via expect or some other means,
please let me know :-)

Regards,
Tobi

[0] https://help.ubuntu.com/community/SSH/OpenSSH/Keys

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: Interaction With Command Shell

Benoît Minisini
Le 16/03/2015 16:31, Tobias Boege a écrit :

> On Mon, 16 Mar 2015, Nigel Verity wrote:
>> Hi
>>
>> I would welcome some advice about interacting with the Linux command shell from within a Gambas application.
>>
>> The requirement is to create a connection with a remote server using SSHFS. The general syntax for this command is:
>>
>> sshfs username@remote-server:/foldername /local-mount-folder
>>
>> There is no option in the SSHFS command to include the user's password on the remote server. When running from a command prompt, once the sshfs command is accepted you are then prompted to enter the password.
>>
>> Is there any way, after executing the SSHFS command (using SHELL, presumably) to monitor for the password prompt and then send the password to the command shell?
>>
>> My aim is to create a dialog in which the user provides the server name, username and password and have Gambas do the rest to create the SSHFS connection.
>>
>
> I have once tried that, specifically with sshfs, too, and failed miserably.
> Your zeroth approximation should be to factor out Gambas and write a shell
> script which can pass the password to sshfs. If you've got that, you almost
> have the solution in Gambas.
>
> There is a program "expect" which was designed for specifically the purpose
> of waiting on a program's output for a specific pattern and then sending a
> given string to its input (i.e. to automate interactive programs). But it
> seems sshfs is putting extra effort into preventing this automation.
>
> I ended up creating a private/public key pair and have the server work with
> that so that I can login using these keys[0]. Maybe this is an option for
> you, too?
>
> If you can trick sshfs into being automated via expect or some other means,
> please let me know :-)
>
> Regards,
> Tobi
>
> [0] https://help.ubuntu.com/community/SSH/OpenSSH/Keys
>

I'm automating scp and ssh daily with Gambas, by detecting when the
password prompt appears (and the ssh key confirmation question too).

It cannot be 100% reliable, because any other program can print
"password:" on its standard output, and apparently there is no way to
know that a program is waiting for input.

But in practise it works.

If there is no clean way to do that, maybe I should make a component
with that, even it's some quick & dirty hack?

--
Benoît Minisini

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: Interaction With Command Shell

Nigel Verity
In reply to this post by Nigel Verity


> Date: Mon, 16 Mar 2015 16:57:05 +0100
> From: Beno?t Minisini <[hidden email]>
> Subject: Re: [Gambas-user] Interaction With Command Shell
> To: mailing list for gambas users <[hidden email]>
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=windows-1252; format=flowed
>
> Le 16/03/2015 16:31, Tobias Boege a ?crit :
> > On Mon, 16 Mar 2015, Nigel Verity wrote:
> >> Hi
> >>
> >> I would welcome some advice about interacting with the Linux command shell from within a Gambas application.
> >>
> >> The requirement is to create a connection with a remote server using SSHFS. The general syntax for this command is:
> >>
> >> sshfs username@remote-server:/foldername /local-mount-folder
> >>
> >> There is no option in the SSHFS command to include the user's password on the remote server. When running from a command prompt, once the sshfs command is accepted you are then prompted to enter the password.
> >>
> >> Is there any way, after executing the SSHFS command (using SHELL, presumably) to monitor for the password prompt and then send the password to the command shell?
> >>
> >> My aim is to create a dialog in which the user provides the server name, username and password and have Gambas do the rest to create the SSHFS connection.
> >>
> >
> > I have once tried that, specifically with sshfs, too, and failed miserably.
> > Your zeroth approximation should be to factor out Gambas and write a shell
> > script which can pass the password to sshfs. If you've got that, you almost
> > have the solution in Gambas.
> >
> > There is a program "expect" which was designed for specifically the purpose
> > of waiting on a program's output for a specific pattern and then sending a
> > given string to its input (i.e. to automate interactive programs). But it
> > seems sshfs is putting extra effort into preventing this automation.
> >
> > I ended up creating a private/public key pair and have the server work with
> > that so that I can login using these keys[0]. Maybe this is an option for
> > you, too?
> >
> > If you can trick sshfs into being automated via expect or some other means,
> > please let me know :-)
> >
> > Regards,
> > Tobi
> >
> > [0] https://help.ubuntu.com/community/SSH/OpenSSH/Keys
> >
>
> I'm automating scp and ssh daily with Gambas, by detecting when the
> password prompt appears (and the ssh key confirmation question too).
>
> It cannot be 100% reliable, because any other program can print
> "password:" on its standard output, and apparently there is no way to
> know that a program is waiting for input.
>
> But in practise it works.
>
> If there is no clean way to do that, maybe I should make a component
> with that, even it's some quick & dirty hack?
>
> --
> Beno?t Minisini

Hi Benoit

I suspect there could be good security reasons why the author(s) of SSHFS keep the password entry separate from the main command string. However, this type of issue cannot be unique to SSHFS, so a Gambas component which can simulate the user interacting with a terminal could have a lot of uses. Handling unexpected error messages, which might appear in a terminal window when you are expecting a prompt of some kind, could make it complicated, though.

Nige
     
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: Interaction With Command Shell

Lewis Balentine

Handling unexpected error messages, which might appear in a terminal window

That of course assumes that there is a terminal windows open to receive
the error messages. :-)

Lewis

On 03/16/2015 04:39 PM, Nigel Verity wrote:

> Hi Benoit
>
> I suspect there could be good security reasons why the author(s) of SSHFS keep the password entry separate from the main command string. However, this type of issue cannot be unique to SSHFS, so a Gambas component which can simulate the user interacting with a terminal could have a lot of uses. Handling unexpected error messages, which might appear in a terminal window when you are expecting a prompt of some kind, could make it complicated, though.
>
> Nige
>    
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming The Go Parallel Website, sponsored
> by Intel and developed in partnership with Slashdot Media, is your hub for all
> things parallel software development, from weekly thought leadership blogs to
> news, videos, case studies, tutorials and more. Take a look and join the
> conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: Interaction With Command Shell

Tobias Boege-2
In reply to this post by Benoît Minisini
On Mon, 16 Mar 2015, Beno?t Minisini wrote:

> Le 16/03/2015 16:31, Tobias Boege a ?crit :
> > On Mon, 16 Mar 2015, Nigel Verity wrote:
> >> Hi
> >>
> >> I would welcome some advice about interacting with the Linux command shell from within a Gambas application.
> >>
> >> The requirement is to create a connection with a remote server using SSHFS. The general syntax for this command is:
> >>
> >> sshfs username@remote-server:/foldername /local-mount-folder
> >>
> >> There is no option in the SSHFS command to include the user's password on the remote server. When running from a command prompt, once the sshfs command is accepted you are then prompted to enter the password.
> >>
> >> Is there any way, after executing the SSHFS command (using SHELL, presumably) to monitor for the password prompt and then send the password to the command shell?
> >>
> >> My aim is to create a dialog in which the user provides the server name, username and password and have Gambas do the rest to create the SSHFS connection.
> >>
> >
> > I have once tried that, specifically with sshfs, too, and failed miserably.
> > Your zeroth approximation should be to factor out Gambas and write a shell
> > script which can pass the password to sshfs. If you've got that, you almost
> > have the solution in Gambas.
> >
> > There is a program "expect" which was designed for specifically the purpose
> > of waiting on a program's output for a specific pattern and then sending a
> > given string to its input (i.e. to automate interactive programs). But it
> > seems sshfs is putting extra effort into preventing this automation.
> >
> > I ended up creating a private/public key pair and have the server work with
> > that so that I can login using these keys[0]. Maybe this is an option for
> > you, too?
> >
> > If you can trick sshfs into being automated via expect or some other means,
> > please let me know :-)
> >
> > Regards,
> > Tobi
> >
> > [0] https://help.ubuntu.com/community/SSH/OpenSSH/Keys
> >
>
> I'm automating scp and ssh daily with Gambas, by detecting when the
> password prompt appears (and the ssh key confirmation question too).
>
> It cannot be 100% reliable, because any other program can print
> "password:" on its standard output, and apparently there is no way to
> know that a program is waiting for input.
>
> But in practise it works.
>
> If there is no clean way to do that, maybe I should make a component
> with that, even it's some quick & dirty hack?
>

I would definitely like to see it. I have a project here which can pipe a
password into sudo and I remember seeing forum threads where others could
automate sshfs mounts but all those approaches didn't work with my sshfs.
(That's why I suspected that they put extra effort into preventing auto-
 mation, be it for their amusement or to discipline users.)

Regards,
Tobi

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: Interaction With Command Shell

Benoît Minisini
Le 16/03/2015 22:44, Tobias Boege a écrit :

> On Mon, 16 Mar 2015, Beno?t Minisini wrote:
>> Le 16/03/2015 16:31, Tobias Boege a ?crit :
>>> On Mon, 16 Mar 2015, Nigel Verity wrote:
>>>> Hi
>>>>
>>>> I would welcome some advice about interacting with the Linux command shell from within a Gambas application.
>>>>
>>>> The requirement is to create a connection with a remote server using SSHFS. The general syntax for this command is:
>>>>
>>>> sshfs username@remote-server:/foldername /local-mount-folder
>>>>
>>>> There is no option in the SSHFS command to include the user's password on the remote server. When running from a command prompt, once the sshfs command is accepted you are then prompted to enter the password.
>>>>
>>>> Is there any way, after executing the SSHFS command (using SHELL, presumably) to monitor for the password prompt and then send the password to the command shell?
>>>>
>>>> My aim is to create a dialog in which the user provides the server name, username and password and have Gambas do the rest to create the SSHFS connection.
>>>>
>>>
>>> I have once tried that, specifically with sshfs, too, and failed miserably.
>>> Your zeroth approximation should be to factor out Gambas and write a shell
>>> script which can pass the password to sshfs. If you've got that, you almost
>>> have the solution in Gambas.
>>>
>>> There is a program "expect" which was designed for specifically the purpose
>>> of waiting on a program's output for a specific pattern and then sending a
>>> given string to its input (i.e. to automate interactive programs). But it
>>> seems sshfs is putting extra effort into preventing this automation.
>>>
>>> I ended up creating a private/public key pair and have the server work with
>>> that so that I can login using these keys[0]. Maybe this is an option for
>>> you, too?
>>>
>>> If you can trick sshfs into being automated via expect or some other means,
>>> please let me know :-)
>>>
>>> Regards,
>>> Tobi
>>>
>>> [0] https://help.ubuntu.com/community/SSH/OpenSSH/Keys
>>>
>>
>> I'm automating scp and ssh daily with Gambas, by detecting when the
>> password prompt appears (and the ssh key confirmation question too).
>>
>> It cannot be 100% reliable, because any other program can print
>> "password:" on its standard output, and apparently there is no way to
>> know that a program is waiting for input.
>>
>> But in practise it works.
>>
>> If there is no clean way to do that, maybe I should make a component
>> with that, even it's some quick & dirty hack?
>>
>
> I would definitely like to see it. I have a project here which can pipe a
> password into sudo and I remember seeing forum threads where others could
> automate sshfs mounts but all those approaches didn't work with my sshfs.
> (That's why I suspected that they put extra effort into preventing auto-
>   mation, be it for their amusement or to discipline users.)
>
> Regards,
> Tobi
>

The idea would be the ability to define the concept of "command that
sometimes asks for a password or something else", which would be linked
with a list of command executable names, a prompt, and what to answer.

As, "of course", each command do as it wants, and often commands run
other commands that could prompt too (for example, svn uses the ssh
protocol, but cannot give it any password, and ask for it several times).

And, "of course", each command must be run in english, as we will not
store the different prompts for all possible languages.

I know the prompts of ssh, scp, and svn (but maybe not all). For other
commands, I need the knowledge of the Gambas community!

If you have other ideas about that, just tell.

Regards,

--
Benoît Minisini

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: Interaction With Command Shell

Tobias Boege-2
On Tue, 17 Mar 2015, Beno?t Minisini wrote:

> >> I'm automating scp and ssh daily with Gambas, by detecting when the
> >> password prompt appears (and the ssh key confirmation question too).
> >>
> >> It cannot be 100% reliable, because any other program can print
> >> "password:" on its standard output, and apparently there is no way to
> >> know that a program is waiting for input.
> >>
> >> But in practise it works.
> >>
> >> If there is no clean way to do that, maybe I should make a component
> >> with that, even it's some quick & dirty hack?
> >>
> >
> > I would definitely like to see it. I have a project here which can pipe a
> > password into sudo and I remember seeing forum threads where others could
> > automate sshfs mounts but all those approaches didn't work with my sshfs.
> > (That's why I suspected that they put extra effort into preventing auto-
> >   mation, be it for their amusement or to discipline users.)
> >
> > Regards,
> > Tobi
> >
>
> The idea would be the ability to define the concept of "command that
> sometimes asks for a password or something else", which would be linked
> with a list of command executable names, a prompt, and what to answer.
>

Oh, no, I meant I'd like to see the code you use to feed scp a password,
in a plain project, just to see if it works here, too, and if I can adapt
it to sshfs. Because it's weird that I give a password to sudo but not to
sshfs.

> As, "of course", each command do as it wants, and often commands run
> other commands that could prompt too (for example, svn uses the ssh
> protocol, but cannot give it any password, and ask for it several times).
>
> And, "of course", each command must be run in english, as we will not
> store the different prompts for all possible languages.
>
> I know the prompts of ssh, scp, and svn (but maybe not all). For other
> commands, I need the knowledge of the Gambas community!
>
> If you have other ideas about that, just tell.
>

Two things:

 - some programs, like sudo, allow to define a prompt. The code could take
   advantage of that if we teach it which programs allow that and how,
 - prompts may also depend on the software version, distribution or
   configuration (I remember there was a program which had a different
   prompt at school than it had at my home computer, might have also been
   sudo).

The class you described in your first paragraph would have essentially no
more data than

  Private $aPrograms As String[] ' Program executable paths
  Private $sPrompt As String ' Prompt (String vs. Like pattern vs. gb.pcre?)
  Private $sAnswer As String ' Answer
  ' or arrays of the latter two.

We never want to save $sAnswer to disk. But the first two depend only on the
machine (on non-sophisticated systems where each user has its own local
version of a program), so they could be saved in a database by the component
requiring only to give the answer each time the Gambas process starts anew.

Regards,
Tobi

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user