How to script file for a Mac with several Terminal commands

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!


Solution 1:

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.