-1

I have few Terminal commands which i'm using so frequently,So i though to automate it to reduce the effort of copy-pasting the commands one by one in terminal and time.

I created a .command file for this but the issue with it is, it is only executing the first statement.

The first statement is connecting to a remote server and it needs a password , for that i usually copy-paste the password. When i changed it to a .command file after executing the first command it is requesting a password in a new window and further commands are not getting executed in the new window.

Does can anyone help/suggest to find a way to do this?

Below is the commands,

#!/usr/bin/expect
set timeout 60
set host 111.111.111.11
set name root 
set password **************

spawn ssh $host -l $name 

expect {
    "(yes/no)?" {
        send "yes\n"
        expect "password:"
        send "$password\n"
    }
    "password:" {
        send "$password\n"
    }
}

expect "#"
# test whether login to host
send "ssh-agent bash\n"
send "ssh-add etlbi-master\n"
send_user "Now you can do some operation on this terminal\n"
send “ssh-add etlbi-master”

Getting the below error,Also not able to enter any commands on the terminal window.

Last login: Thu Jun 20 17:39:57 2019 from 111.111.111.11
root@Ubuntu-1689-xenial-64-minimal ~ # Now you can do some operation on this terminal
usage: send [args] string
    while executing
"send “ssh-add etlbi-master”"
    (file "/Users/sand/Documents/google/newtest.command" line 25)
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.


[Process completed]

Note: i'm the admin.

Thanks in advance!

  • To me, it looks like some string is not being escaped. At least that would explain the hanging prompt. Maybe your newlines are bugging out the interpreter or possibly a char in your password. – user136952 Jun 20 at 17:49
2

The final line of your script is using curved quoted instead of straight quotes.
“ and ” have been used in place of ".

Replace the line

send “ssh-add etlbi-master”

with

send "ssh-add etlbi-master"

Look at the syntax highlighting of your script in your question — the ‘string’ is not red but black.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .