Home > OS >  For help on writing a shell script called expect on other nodes, how to obtain the return value judg
For help on writing a shell script called expect on other nodes, how to obtain the return value judg

Time:09-30

Purpose is by calling the shell script with expect from a node automatically log in to the node b, then verify whether a directory on the node b ok files to arrive, if not verified sleep again after a period of time until the scan 5 times no file, or scan to file the exit after 0, want to pass inspection schedule every day to run a shell script,
Now write a really don't know how to obtain the find the command result then in a shell script below if then, usually with the shell is not very skilled, hope everyone to help see,
#!/bin/bash
File_pwd='/bigdata/data/20190902'
Usr/bin/expect & lt; -Set the timeout 5
Spawn SSH $1 @ $2
Expect {
"(yes/no)?" {the send "yes \ n"}
"Password:" {send "hadoop \ n"}
Eof}
Send "the find ${file_pwd} | awk -f. ' ' '{print $2}"
Expect eof
Interact
EOF

CodePudding user response:

Don't know how to convey variables to expect the shell, so I will only in the expect output a value or a string, and then back to the shell to get the value, to determine, this way,

 
#!/bin/bash

The function () {
File_pwd='/bigdata/data/20190902'
Usr/bin/expect & lt; Set the timeout 5
Spawn SSH $1 @ $2
Expect {
"(yes/no)?" {the send "yes \ n"}
"Password:" {send "hadoop \ n"}
Expect "root @
"Send "ls test. TXT & gt;/dev/null & amp; & Echo 0 | | echo 1
"Send "exit \ r"
EOF
}
Status=` function | * * * * * `

Like this, can have some output function this function, through the processing, the echo of the string, filtering, assign a value to a variable status, and then to judgment, then add some actions in the rear

CodePudding user response:

reference 1st floor zhouchao6 response:
don't know how to convey variables to expect the shell, so I will only in the expect output a value or a string, and then back to the shell to get the value, judging by this way

 
#!/bin/bash

The function () {
File_pwd='/bigdata/data/20190902'
Usr/bin/expect & lt; Set the timeout 5
Spawn SSH $1 @ $2
Expect {
"(yes/no)?" {the send "yes \ n"}
"Password:" {send "hadoop \ n"}
Expect "root @
"Send "ls test. TXT & gt;/dev/null & amp; & Echo 0 | | echo 1
"Send "exit \ r"
EOF
}
Status=` function | * * * * * `

Like this, can have some output function this function, through the processing, the echo of the string, filtering, assign a value to a variable status, and to judge, then add some operating behind

Trouble ask next last step function how to obtain the results ah, baidu along while didn't find usage: , and seemed to try to send" ls test. TXT & gt;/dev/null & amp; & Echo 0 | | echo 1 "this sentence must be 0, there is no test file role

CodePudding user response:

Reference
trouble ask next last step function how to obtain the results ah, baidu along while not find usage, and seemed to try to send "ls test. TXT & gt;/dev/null & amp; & Echo 0 | | echo 1 "this sentence must be 0, there is no test file role ah


Take as a result, the status=` function | * * * * * `
Perform this function, then pipe processing
Ls test. TXT & gt;/dev/null & amp; & Echo 0 | | echo should not is 0, 1 have a test. TXT echo 0 this file, otherwise the output 1, which you can literally find a machine to test
  • Related