通过shell脚本文件向expect脚本传递参数

通过shell脚本文件向expect脚本传递参数

我需要在 ssh 脚本的命令行下从 shell 脚本传递参数

例如 :

#!/usr/bin/expect
spawn ssh [email protected] "cm1+passingparameters.sh;cmd2"

我现有的脚本123.sh运行良好。

#!/usr/bin/expect

spawn ssh [email protected] "/pstools/85419/jre/bin/java -Xms1024M -Xmx1024M -Dhttps.protocols=TLSv1.2 -Djdk.tls.client.protocols=TLSv1.2 -jar /app1/non/psoft/85419/gu1/gust/classes/SVC_TestS.jar https://decorp6-- tst4.custhelp.com/services/rest/connect/v1.3/incidents userid password ssow.proxy.com port;cd /app01/nonhr/psoft/85419/gucq1/gecust;mail -s 'OTO' [email protected] < logs.txt"

expect "password"

send "mypassword\r"

interact

expect eof

我想要 2 个a.sh脚本b.sh

a.sh应如下(注意上述原始脚本的变化PASS b.sh after .jar

#!/usr/bin/expect

spawn ssh [email protected] "/pstools/85419/jre/bin/java -Xms1024M -Xmx1024M -Dhttps.protocols=TLSv1.2 -Djdk.tls.client.protocols=TLSv1.2 -jar /app1/non/psoft/85419/gu1/gust/classes/SVC_TestS.jar PASS b.sh;cd /app01/nonhr/psoft/85419/gucq1/gecust;mail -s 'OTO' [email protected] < logs.txt"
expect "password"

send "mypassword\r"

interact

expect eof

b.sh应该如下

#!/user/ksh
 https://decorp6--tst4.custhelp.com/services/rest/connect/v1.3/incidents userid password ssow.proxy.com port

答案1

思考您询问如何将各种参数插入远程java命令,这可能很简单

#!/usr/bin/expect

if {[llength $argv] == 0} {
  puts stderr "Usage: todo fixeme"
  exit 1
}

set the_args [join $argv]

spawn ssh [email protected] "/pstools/85419/jre/bin/java ... -jar /app1/non/psoft/85419/gu1/gust/classes/SVC_TestS.jar $the_args; ..."
...

然后你可以通过以下方式运行上面的内容:

$ whatyousaveditas https://decorp6--tst4.cu... user pass ...

相关内容