我想從本地機器運行我的python腳本。但名爲script.py
的python腳本位於遠程服務器中,它具有一些參數和參數。 我曾嘗試:在python中使用ssh從遠程服務器運行腳本
#!/usr/bin/python
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='x.x.x.x', port=22, username='root', password='passwd')
stdin, stdout, stderr=ssh.exec_command('python /root/file/script.py') #It has some argument I want to use them from my local machine
for i in stdout.readlines():
print i.strip('\r\n')
ssh.close()
script.py
有一些爭論。我應該如何改變這個腳本以便從我的本地機器使用參數script.py
?
你熟悉'sys.argv'嗎?你可以在腳本中使用它來傳遞終端中的參數! https://docs.python.org/2/library/sys.html#sys.argv – Kasramvd 2015-02-23 07:54:08
是的,我是...但在腳本中使用script.py的參數是可能的?怎麼樣? – MLSC 2015-02-23 07:59:08
你可以在'ssh.exec_command'函數中傳遞它們! (但我不知道這個功能支持!),但'os.system'支持! – Kasramvd 2015-02-23 08:04:01