シェルスクリプトファイルから期待スクリプトにパラメータを渡す

シェルスクリプトファイルから期待スクリプトにパラメータを渡す

シェルスクリプトからsshスクリプトのコマンドラインにパラメータを渡す必要があります

例えば ​​:

#!/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.shb.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 ...

関連情報