【发布时间】:2016-05-12 23:34:25
【问题描述】:
您好,我是 Expect 脚本的新手。我试图使用 ssh spawn 调用远程脚本并将命令行参数传递给远程脚本。但是在远程脚本中我得到空值。请帮助解决这个问题。在 except 脚本中传递参数有问题吗?
本地 Expect 脚本
#!/usr/bin/expect
set hana_schema [lindex $argv 1]
set table [lindex $argv 2]
set condition [lindex $argv 3]
set yyyymm [lindex $argv 4]
set targetdir [lindex $argv 5]
set split [lindex $argv 6]
set timeout 120
set ip XXXX.XXX.XX.XX
set user name
set password pass
set script /path-to-script/test.sh
# here I spawn a shell that will run ssh and redirect the script to ssh's
spawn sh -c "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $user@$ip bash $hana_schema $table $condition $yyyymm $targetdir $split < $script" "$hana_schema" "$table" "$condition" "$yyyymm" "$targetdir" "$split"
expect "Password:"
send "$password\r"
# and just wait for the script to finish
expect eof
远程脚本 test.sh
hana_schema=$1
table=$2
condition=$3
yyyymm=$4
targetdir=$5
split=$6
echo "$hana_schema"
echo "$table"
echo "$condition"
echo "$yyyymm"
echo "$targetdir"
echo "$split"
【问题讨论】: