0
Hello Im newbie to Expect scripting。我試圖使用ssh spawn調用遠程腳本,並將命令行參數傳遞給遠程腳本。但在遠程腳本中,我獲取空值。請幫助解決這個問題。除了腳本中傳遞參數的問題?將參數從本地腳本傳遞到遠程腳本,使用除了
本地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 [email protected]$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"
謝謝@Glenn Jackman。它傳遞參數。像通過使用spawn ssh如何以root身份登錄一樣,很容易懷疑。 – marjun
如何將命令行參數傳遞給tcl中的過程? – marjun
命令行參數存儲在全局'$ argv'列表中,所以你可以通過'myproc $ argv'來傳遞一個列表,或者'myproc {*} $ argv'來傳遞所有的單個元素,或者你可以不帶任何參數地調用myproc,並在裏面執行'proc myproc {} {global argv; foreach arg $ argv {...' –