0

While logging into my remote server it expects a user input, it's bash_profile is modified in such a way.

[nikhil]$ cat .bash_profile
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
read -p "enter your name " Name
echo $Name

How can i login into this remote server using ssh and pass that input through script.

1
  • Please edit your question and provide information about what you tried and what it did or did not do.
    – dessert
    Nov 21, 2019 at 9:13

1 Answer 1

0

Install expect:

apt-get install expect

Run following script:

$ expect <<EOF
set timeout -1

spawn ssh -o "StrictHostKeyChecking=no" root@server

expect "root@server's password:"
send -- "12345678PASSWORD\r"
expect "enter your name "
send -- "susan\r"
expect "root@server"
send -- "echo $$\r"
send -- "exit\r"
expect eof
EOF

Adapt following:

  • root@server with your actual server connection parameters
  • obviously the password
  • the name you want to provide to the script inside .bash_profile on the target server
  • the actual command you want to run on the target server (instead of echo $$)

You must log in to answer this question.

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