0

I am trying to use pexpect and pxssh to automate some tasks. I am not very familiar with python. I would like to run a shellscript with some arguments on a server. But the shellscript is hosted locally.

I am now trying to do it like this:

s = pxssh.pxssh()
s.login(host, user, pass)

f = open("./connect.sh", "r")
for line in f:
    s.sendline(line)

s.prompt()
print s.before

connect.sh has an awk one liner. So it reads one line, and sends it directly to the server via pxssh. This works.

However, I want to pass arguments to the shellscript. The awk one liner has a $1 and $2 in it, so they need to be replaced. I think I could manually replace $1 with the first argument, and $2 with the second, so I form a new awk command, and then send the new command to the server with pxssh. But I think there is a smarter way of doing that. So what is the correct way to do this?

Carlito
  • 805
  • 10
  • 20
  • I recommend using Fabric library for automating remote scripts with python – sp4ke Apr 04 '13 at 15:36
  • Could you tell why fabric is better for this task? Note: my script isn't remote, but I need to execute it remotely. – Carlito Apr 08 '13 at 15:43
  • With an initial disclaimer that I am not all that clued up on security, the first thing I would try would be to use scp to copy the script (giving it a randomly generated name?) to an appropriately permissioned temp dir, run it, then delete it. Something like fabric is probably more general though (and I have never used it). – D.J.Duff Apr 29 '13 at 07:28

0 Answers0