Remoting over SSH

Discussion in 'Python' started by Hussein B, Jul 7, 2009.

  1. Hussein B

    Hussein B Guest

    Hey,
    I want to perform commands on a remote server over SSH.
    What do I need?
    Thanks.
     
    Hussein B, Jul 7, 2009
    #1
    1. Advertising

  2. Hussein B

    alex23 Guest

    alex23, Jul 7, 2009
    #2
    1. Advertising

  3. Hussein B

    Tim Harig Guest

    On 2009-07-07, Hussein B <> wrote:
    > I want to perform commands on a remote server over SSH.
    > What do I need?


    catb.org/esr/faqs/smart-questions.html

    There are many ways to remote using ssh. If we know what you are trying to
    do, maybe we could give you a better answer. If you just want to open the
    python interpreter interactively on another host you can do something like:

    ssh -t user@host python

    That will allow you send "commands" to the python interpeter. You could
    write a script and pipe it into the interpreter:

    cat script.py | ssh -t user@host python

    Maybe you want to open an ssh connection and send shell commands from a
    python script. You can do that using one of the popen2 functions:

    http://docs.python.org/library/popen2.html
     
    Tim Harig, Jul 7, 2009
    #3
  4. "Hussein B" <> wrote:

    > Hey,
    > I want to perform commands on a remote server over SSH.
    > What do I need?
    > Thanks.


    Access privileges for the remote machine.

    - Hendrik
     
    Hendrik van Rooyen, Jul 8, 2009
    #4
  5. Hussein B wrote:
    > Hey,
    > I want to perform commands on a remote server over SSH.
    > What do I need?
    > Thanks.
    >

    Hi,
    If you want to use the SSH2 protocol into a python code, you should
    take a look at this module: paramiko [1].

    [1] http://www.lag.net/paramiko/

    Regards,
    Lucas.
     
    Lucas Carvalho, Jul 8, 2009
    #5
  6. Hello!
    I wrote a litle program that send commands to many cluster nodes:

    #!/usr/bin/env python
    #By: Djames Suhanko

    #servers list

    sincroniza =["server1.domain","server2.domain", "server3.domain"]

    import pexpect
    import sys
    from threading import Thread

    #the user and pass can be in ini file.

    #Test parameters list

    try:
    if sys.argv[3]:
    pass
    except:
    print "Use: " + "script" + " <command> <user> <pass>"
    sys.exit()

    #This function send the command in argument
    def executor(command,username,password,server):
    a = 'ssh ' + username + '@' + server
    foo = pexpect.spawn(a)
    foo.expect('.*ssword:')
    foo.sendline(password)
    foo.sendline('su')
    foo.expect('.*sword:')
    foo.sendline('root_password_here')
    foo.sendline(command + '&& exit')
    print "command to: " + server + "..........[OK]"
    foo.sendline('exit')
    foo.expect('.*osed.')
    foo.interact()

    #make a list
    tasks = []

    #theading loop
    for i in sincroniza:
    t = Thread(target=executor,args=(sys.argv[1],sys.argv[2],sys.argv[3],i))
    t.start()
    tasks.append(t)

    #wait the end
    for t in tasks:
    t.join()

    it's all!
    On Wed, Jul 8, 2009 at 9:15 AM, Hendrik van Rooyen<> wrote:
    > "Hussein B" <> wrote:
    >
    >> Hey,
    >> I want to perform commands on a remote server over SSH.
    >> What do I need?
    >> Thanks.

    >
    > Access privileges for the remote machine.
    >
    > - Hendrik
    >
    >
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >




    --
    Djames Suhanko
    LinuxUser 158.760
     
    Djames Suhanko, Jul 8, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. someone

    FTP over SSL vs FTP over SSH

    someone, Apr 24, 2004, in forum: Java
    Replies:
    1
    Views:
    4,591
    iksrazal
    Apr 25, 2004
  2. loial
    Replies:
    0
    Views:
    405
    loial
    Feb 3, 2009
  3. loial
    Replies:
    0
    Views:
    406
    loial
    Feb 10, 2009
  4. Tench Johnson
    Replies:
    1
    Views:
    296
    Biff Tannen
    Apr 23, 2010
  5. salamond

    net/ssh in ruby. ssh.exec fails

    salamond, Feb 17, 2011, in forum: Ruby
    Replies:
    0
    Views:
    248
    salamond
    Feb 17, 2011
Loading...

Share This Page