脚本登录远端服务器并执行命令


#!/bin/sh

set timeout 30
spawn ssh <username>@<server_ip>
expect {
"*yes/no*" { send "yes\r"; exp_continue}
"*Password:*" {send "password\r"}
}
expect "*#*"
send "pss\r"
interact

你可能感兴趣的:(脚本登录远端服务器并执行命令)