1

I need to connect from a Windows machine to a remote Linux server and execute a Perl script. I've tried using

command = "perl /usr/local/xfer/file.pl -ssh root@"+hostname+" -pw password -batch"
pid = subprocess.Popen(command, shell=True)

but it tells me Can't open perl script "usr/local/xfer/file.pl'": No such file or directory.

What am I doing wrong here, and how can I get it to work?

1 Answer 1

2

The command above uses the Perl installation on Windows but you said the script is located on a Linux server.

So you need to wrap the invocation in a call to ssh:

child = subprocess.Popen(['plink', '-ssh', 'user@server', 'perl', '/usr/local/xfer/file.pl', 
            '-ssh', 'root@'+hostname, '-pw', 'password', '-batch'], shell=True)

Note: Never ever use the "string command" version of subprocess.Popen(), always pass command and arguments as a list.

Back to your problem: This will start plink (command line version of Putty since Windows doesn't have ssh(1)) with all the other list elements as arguments.

Note that the Putty Agent must run for this to work, otherwise plink will ask for a password. See the manual for details.

Sign up to request clarification or add additional context in comments.

1 Comment

This helped a lot. After I put plink.exe into my python path, all I really needed for it to work was subprocess.call(['plink', '-ssh', '%s@%s' %(USER,HOST), '-pw', PASSWORD, 'perl', '//usr/local/xfer/file.pl'], shell=True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.