透過shell腳本檔案傳送參數

透過shell腳本檔案傳送參數

我需要在 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 ...

相關內容