使用执行脚本登录到远程服务器后无法执行 shell 命令

Not able to execute shell commands after login to remote server using execute script

我正在使用执行脚本登录远程服务器。我能够成功登录,但登录后我无法在远程服务器上执行任何命令,如 cd、pwd 等

我尝试同时使用 .exp 和 .sh,但都遇到了同样的问题。执行脚本后停止执行。

execute_script.exp 文件

#!/usr/bin/expect

eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user@****
expect "Password:"
send "password\r"
send "\r"
expect "user"
send "pwd\r"

bash_script.sh

#!/usr/bin/env bash

expect <<- DONE
  set timeout -1

  spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user@****

  # Look for passwod prompt
  expect "Password:"
  # Send password aka $password
  send -- "password#\r"
  # send blank line (\r) to make sure we get back to gui
  send -- "\r"
  send "pwd\r"
  expect eof
DONE

这是执行 .exp 脚本后发生的情况。请告知我在做什么错误,或者让我知道任何其他方法。我的目标是通过 ssh 连接到远程服务器并从特定路径

执行 python 脚本
SSDL-231234:common user$ expect execute_script.exp 
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user@****
Password:
Last login: Sun Sep 15 20:10:19 2019 from ****

发送密码后需要等待远程服务器的提示。

send -- "password#\r"
set prompt "(#|%|>|\$)"
expect -re $prompt
send "pwd\r"
set prompt "(#|%|>|\$)"