plink 的簡易教學: 自動連到遠端機器下批次指令(ssh 版)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://mqjing.blogspot.tw/2008/05/python-ssh-plinkexe.html | |
plink 的簡易教學 | |
使用 ssh telnet 連線 | |
c:\plink -ssh login.example.com | |
login as: | |
自動連上(包含 username 與 passwd) | |
c:\plink -ssh login.example.com -l(空格)名字 -pw(空格)密碼 | |
在遠端機器上, 批次執行一堆指令 | |
c:\plink -ssh login.example.com -l(空格)名字 -pw(空格)密碼 命令1;命令2 | |
ex: | |
c:\plink -ssh login.example.com -l(空格)名字 -pw(空格)密碼 ls;echo Hello World;ls | |
import os | |
host="192.168.0.1" | |
user="username" | |
passwd="passwd" | |
com_array=["cd ~jing", | |
"ls -la", | |
"ftpget -u jing -p passwd ipaddress a.zip b.zip", | |
"exit"] | |
# Step 1: the remote command | |
Batch_command="" | |
for command in com_array: | |
Batch_command=Batch_command+command+";" | |
#print Batch_command | |
print "Batch_command="+Batch_command | |
# Step 2: the user info | |
UserLogin="-l "+user+" "+"-pw "+passwd | |
# Step 3: the plink command | |
PlinkCommand="plink.exe -ssh "+host+" "+UserLogin+" "+Batch_command | |
print "PlinkCommand="+PlinkCommand | |
os.system(PlinkCommand); | |
print "Job done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment