简体   繁体   中英

manual / script ssh difference

I am able to log into a machine using SSH manually and using a Python script. Both succeed in logging in.

From the manual attempt, if I run the script signmes1.py, it works.

From the Python script, if I run the same script using the command

os.system("python signmes1.py")

it does not work, and has the following error. The file it is complaining about definitely exists and loads if I run the script manually. Why would it make any difference if I am using exactly the same command but in a script?

Traceback (most recent call last):
  File "signmes1.py", line 12, in <module>
    with open("result1.txt", "r") as my_file:
IOError: [Errno 2] No such file or directory: 'result1.txt'

The code I use in my script to log in is the following:

import ssh
import os

s = ssh.Connection(host = 'ipaddress', username = 'server1', password = 'xxxx') 

Where ipaddress is the ipaddress, and password is my password. The log in works well as far as I can see, I can copy things over to the remote server and copy them back to the local machine.

Still not sure. Is your code something like this?

import ssh
import os

s = ssh.Connection(host = 'ipaddress', username = 'server1', password = 'xxxx') 
os.system("python signmes1.py")

If yes, things wont run fine for you. If no, please edit the question and paste the full code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM