我正在尝试运行一个expect脚本,它应该在远程linux服务器上运行bash脚本。 bash脚本用于根据expect脚本发送的参数重新启动strongswan IPSec隧道。 这是我的期望剧本:
#log_user 0
set prompt {\$ >}
expect -re $prompt
set ip 192.168.0.1
set user user
set password 4p4ssw0rd
set target [lindex argv 0]
spawn ssh -p 2228 "$user\@$ip"
expect "password:"
send "$password\r";
expect ">"
send "su -\r"
expect "Password:"
send "$password\r"
expect "#"
send "sh /usr/local/bin/ipsec_fixer.sh $target; exit\r"
expect "#"
这是远程脚本:
target=$1
if [[ -n "$target" ]]; then
value=`grep -i $target /etc/ipsec.conf -A1 |awk '{print $2}'| tail -n 2 | sed 's/0$//'`
declare -a args
args=( $(grep "$value"* /etc/ipsec.conf | awk '{print $2}') )
for each in ${args[@]}; do ipsec down $each; sleep 3; ipsec up $each ; done
else
exit 2
fi
期望脚本运行,但我得到以下输出:
/usr/local/bin/fix_ipsec avpnconnection
spawn ssh -p 2228 user@192.168.0.1
user@192.168.0.1's password:
Last login: Sun Dec 11 05:40:55 2016 from 192.168.0.232
sh /usr/local/bin/ipsec_fixer.sh argv; exit
021 no connection named "-c"
021 no connection named "-c"
021 no connection named "-c"
021 no connection named "-c"
logout
user@remote:/home/login >
我不知道发生了什么事。请问我做错了什么?
答案 0 :(得分:1)
我想我已经明白了:奇怪的看起来
var val1 = document.forms.fname.elements.iname.value;
console.log(val1);
var val2 = fname.iname.value;
console.log(val2);
行来自远程系统的shell。
我的期望脚本现在看起来像这样:
<form name='fname'>
<input name='iname' value="42">
</form>
到目前为止它完成了这项工作......
答案 1 :(得分:0)
你可以使用
ssh -t -p 2228 user@192.168.0.1 "sudo /bin/sh /usr/local/bin/ipsec_fixer.sh $target"
并使用SSH Key-Based Authentication。
至于您收到的消息,您启动的脚本是否可能会影响当前的SSH连接?