我写了一个用于双重身份验证的shell脚本。 这是在执行if语句时发生错误。Shell脚本:给出错误无效命令名称“server1”
#!/usr/bin/Expect
#!/bin/bash
set cpPass "App12345"
set server [lindex $argv 0]
set pass "[email protected]"
set app "app1"
set appPass "[email protected]"
spawn ssh [email protected]$server.corp.clll.com
expect {
"(yes/no)?" {
send "yes\r"
expect "password:"
send "$cpPass\r"
}
"password:" {
send "$pass\r"
}
}
expect "bash"
send "su - $app\r"
expect "Password:"
send "$appPass\r"
if [ "$server" == "server1" ]
then
send "cd /ngs/app/genevad/QA/site/distribution/servers1\r";
else
send "sqlplus gqa_owner/App#[email protected]:1700/app1D\r";
fi
interact
该错误是这样的上命令 ./script.sh server1的执行
invalid command name "server1"
while executing
""$server" == "novello" "
invoked from within
"if [ "$server" == "novello" ]"
(file "./script.sh" line 28)
我曾尝试过各种组合中,如果这样的: 如果[$服务器== “诺维罗”] if [$ server -eq“novello”] if [“$ server”-eq“novello”] etc但仍无法使用。任何建议/解决方案?
根据anubhava和dinesh的回答,更新脚本如下:1.删除#!/ bin/bash 2.更改后的代码:if {$ server ==“server1”} { send“cd/ngs/app/genevad/QA/site/distribution/servers1 \ r”; } else { send“sqlplus gqa_owner/App#[email protected]:1700/app1D \ r”; } – anon 2014-11-04 06:56:39
请勿使用'expect'登录'ssh'!使用'ssk-keygen'并共享公钥! – 2014-11-04 07:29:49