long.manager-web.1.13.0.source-code.exec_cmd.exp Maven / Gradle / Ivy
The newest version!
#!/usr/bin/expect
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
set remoteHost [lindex $argv 0]
set remoteUser [lindex $argv 1]
set password [lindex $argv 2]
set cmdTimeout [lindex $argv 3]
set runCommand [lindex $argv 4]
set remotePort [lindex $argv 5]
# use the public key to identify
if { $password == "" } {
spawn ssh -p ${remotePort} -i ~/.ssh/inlong_rsa ${remoteHost} -l ${remoteUser} "${runCommand} && echo \\#SUCCESS\\# || echo \\#fail\\#"
} else {
spawn ssh -p ${remotePort} ${remoteHost} -l ${remoteUser} "${runCommand} && echo \\#SUCCESS\\# || echo \\#fail\\#"
}
set timeout ${cmdTimeout}
expect {
"*yes/no)?" {send "yes\n"; exp_continue}
"*assword:" {send "${password}\n"; exp_continue }
"Last login:" {}
"#SUCCESS#" {}
"#fail#" {exit 1 }
"*No route to host" {exit 2}
"Permission denied" {exit 3}
"*Host key verification failed*" {exit 4}
timeout { exit 5 }
eof { exit 6 }
}