I have written a shell script for double authentication. This is giving an error while execution in if statement.
#!/usr/bin/Expect
#!/bin/bash
set cpPass "App12345"
set server [lindex $argv 0]
set pass "App12345@123"
set app "app1"
set appPass "app@1013"
spawn ssh user1@$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
The error is like this on execution of command ./script.sh server1
invalid command name "server1"
while executing
""$server" == "novello" "
invoked from within
"if [ "$server" == "novello" ]"
(file "./script.sh" line 28)
I have tried various combinations in if like : if [ $server == "novello" ] if [ $server -eq "novello" ] if [ "$server" -eq "novello" ] etc but still not working. Any suggestions/Solutions to it?
Problem is here:
#!/usr/bin/Expect
#!/bin/bash
You cannot have 2 shebangs in same Unix script. Only first will be in effect and second will be ignored. Hence your script must be fully expect compliant script (since that is first one here - should be lowercase expect though).
Moment you try to use a bash syntax in it, you will get errors since that bash specific script will be interpreted by expect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With