2016-01-08 133 views
-3

我想通过ssh登录一个ubuntu主板并在其中执行一些命令。尽管下面的代码登录它不做一个CD或执行我想要的文件。可能是什么问题?自动ssh登录脚本,期望

spawn ssh [email protected] 
expect "password:" 
send "odroid\r" 
interact 
expect "[email protected]:~$ " 
send "cd pixhawk_ws_wstool/devel/lib\r" 
interact 
send "./slam_demo/slam\r" 
interact 
+0

1)使用密钥设置验证。 2)不要使用密码,让自己的生活更轻松,更安全。 – Jakuje

回答

0

不需要interact,除非您需要手动交互。

# We escaped the `$` symbol with backslash to match literal '$' 
# The last '$' sign is to represent end-of-line 
set prompt "#|>|%|\\\$ $" 
spawn ssh [email protected] 
expect "password:" 
send "odroid\r" 
expect -re $prompt 
send "cd pixhawk_ws_wstool/devel/lib\r" 
expect -re $prompt 
send "./slam_demo/slam\r" 
expect -re $prompt