シェルスクリプトファイルを介してスクリプトを予想するパラメータを渡す

シェルスクリプトファイルを介してスクリプトを予想するパラメータを渡す

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

a.shスクリプト2つが欲しい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 ...

おすすめ記事