Remoting over SSH

H

Hussein B

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

Tim Harig

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
 
H

Hendrik van Rooyen

Hussein B said:
Hey,
I want to perform commands on a remote server over SSH.
What do I need?
Thanks.

Access privileges for the remote machine.

- Hendrik
 
D

Djames Suhanko

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top