Python and ssh for remote login

Noah noah at neo.co.tz
Wed Oct 5 15:06:59 EDT 2016


On 5 Oct 2016 22:02, "Ethan Furman" <ethan at stoneleaf.us> wrote:
>
> On 10/05/2016 10:46 AM, Noah wrote:
>
>> I would like to use a python script to ssh into a server using a username
>> and password [...]
>
>
> I've written a module called scription to help with scripts; it supports
giving passwords to programs like ssh.
>

Hi Ethan and for writting this script.

> Here's an example from one of my utility scripts:
>
> -- 8< ---------------------------
> #!/usr/local/bin/python
>
> from getpass import getpass
> from antipathy import Path
> from scription import Command, Execute, Main, OPTION, REQUIRED
>
> ...
>
> @Command(
>     repo=('repository to pull [default: all]', OPTION),
>     path=('base path to search', OPTION, 'p', Path),
>     )
> def pull(repo, *path):
>     '''
>     retrieve remote change sets
>     '''
>     password = getpass('[mercurial] password: ')
>     target = repo
>     for repo in workhorse(*path):
>         if target and repo.filename != target:
>             continue
>         history = Execute(('hg', 'pull'), cwd=repo, password=password,
pty=True)
>
> -- 8< ----------------------------
>
> and in use:
>
> ==================================
>
> $ hgc --help
> Available commands/options in hgc
>    incoming  displays changesets in remote repo not present locally
>    list      displays all repos
>    log-date  displays all log entries for matching date
>    outgoing  displays changesets in remote repo not present locally
>    parent    displays parent of active branch
>    pull      retrieve remote change sets
>    push      send local changesets to remote repo
>    status    display status for each repo
>    update    update active files to latest version
>
> $ hgc pull
> [mercurial] password:
>
> ...
> ===================================
>
> It's available via pip.  Feedback welcome.  :)
>

I will pip it too and try it out and give some feedback based on my use
case.

Thanks a lot.

> --
> ~Ethan~
> --

Noah



More information about the Python-list mailing list