chen wen
chen wen

Reputation: 11

There is some problem about expect in linux,and raspberry

There is some problem in my system, I write a script shell just like thie,

#!/usr/bin/expect
spawn ssh -p$port $username@$ip

expect {
"*yes/no" { send "yes\r";exp_continue}
"*password:" { send "pass"}
}
#expect '$*' {send "sudo systemctl stop wind_dete\r"}
expect '$*' {send 'sudo pkill mysql'}
expect "$*" {send "sudo  mkdir test\r"}
interact

but anyway,this expect '$*' {send 'sudo pkill mysql'} can't execute,but expect "$*" {send "sudo mkdir test\r"} execute success. when I execute expect xx.sh,there show this

:~ $ sudo pkill mysql
:~ $ exit

this is executed successd, I can't get any idea about this, that's why lead this case, and how can I pkill mysql from one of my server. I really need help, and I will appreciate your idea and suggestion.

Upvotes: 0

Views: 154

Answers (1)

Colin Macleod
Colin Macleod

Reputation: 4382

Expect is based on the Tcl language, so Tcl syntax must be used for strings. Single quotes ' have no special meaning in Tcl and will treated literally, so expect '$*' will look for a pattern which starts and ends with a single quote, which is unlikely to match anything in practice. Double quotes " can be used to enclose a string. For more details see https://www.tcl-lang.org/man/tcl8.6/TclCmd/Tcl.htm#M8 .

Upvotes: 2

Related Questions