我正在尝试编写一个 shell 脚本,在远程服务器上创建一些目录,然后使用 scp 将文件从我的本地机器复制到远程。这是我到目前为止所拥有的:
ssh -t user@server<<EOT DEP_ROOT='/home/matthewr/releases' datestamp=$(date +%Y%m%d%H%M%S) REL_DIR=$DEP_ROOT"/"$datestamp if [ ! -d "$DEP_ROOT" ]; then echo "creating the root directory" mkdir $DEP_ROOT fi mkdir $REL_DIR exit EOT scp ./dir1 user@server:$REL_DIR scp ./dir2 user@server:$REL_DIR
每当我运行它时,我都会收到以下消息:
Pseudo-terminal will not be allocated because stdin is not a terminal.
脚本永远挂起。
我的公钥在服务器上是受信任的,我可以很好地运行脚本之外的所有命令。有任何想法吗?
尝试ssh -t -t(或ssh -tt简称)强制分配伪 tty,即使 stdin 不是终端。
ssh -t -t
ssh -tt
从 ssh 手册页:
-T Disable pseudo-tty allocation. -t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.