1. 安装好SSHLibrary库后,需要运行shell脚本,但此脚本中运用到了JAVA_HOME,登录Executing command命令运行时,报找不到JAVA_HOME,查了下才了解到ssh作为non-login方式进入,无法触发/etc/profile的执行,需要将JAVA_HOME加入到/etc/bashrc中才有效。因为 原来是在/etc/profile中,只有用户登录时才会执行,而/etc/bashrc在shell脚本打开时,都会执行。
2. 在使用put file时遇到问题,只能从windowns本机上传到服务器的/root下,其他都会出错,从而认识了paramiko的使用,如下
import paramiko
username = "XX"
password = "XX"
hostname = "IP"
port = 22
try:
t = paramiko.Transport((hostname, port))
t.connect(username=username, password=password)
sftp =paramiko.SFTPClient.from_transport(t)
sftp.put("E://work//WebTest//file.conf", "/home/w/share/abcd.txt")
t.close();
except Exception, e:
import traceback
traceback.print_exc()
try:
t.close()
except:
pass
3.在sshlibrary库中,Execute Command经常会在一个新的shell中执行,这导致在执行前后的命令时环境是会改变的,而Write和Read Until便可以在同一个shell中执行。如下:
Write | cd .. |
|
Write | echo Hello from the parent directory! |
|
${output}= | Read Until | directory! |
Should End With | ${output} | Hello from the parent directory! |
4.在使用sshlibrary库的Put Directory时,需要注意windows系统与unix系统的目录分隔符的不同,因为RIDE是在windows下运行,如下:
Put Directory | E:/test | \\tmp |