1 Pluspunkt 0 Minuspunkte

Ich habe ein Linux Expect Script

#!/usr/bin/expect
command=$1
set timeout 20
spawn ssh loginuser@10.0.0.12
expect "password:"
send "t0ps3cr3t\r"
expect "> "
send "sudo -i\r"
expect "password:"
send "t0ps3cr3t\r"
expect "# "
send "$command\r"
send "exit\r"
expect eof

Wie kann ich Parameter an das Script übergeben und als Variablen übernehmen wie z.B command?

von  

1 Antwort

0 Pluspunkte 0 Minuspunkte

In Expect kannst du Parameter über die Variable $argv übernehmen.

#!/usr/bin/expect

set command [lindex $argv 0]

set timeout 20
spawn ssh loginuser@10.0.0.12
expect "password:"
send "t0ps3cr3t\r"
expect "> "
send "sudo -i\r"
expect "password:"
send "t0ps3cr3t\r"
expect "# "
send "$command\r"
send "exit\r"
expect eof
von (728 Punkte)