最近写个shell脚本,功能就是ssh远程登录服务器,执行一些操作,以及使用FTP下载一些文件,但在执行过程中,碰见了几个错误,记录一下。
错误1
ssh登录提示,报错信息的字面意思是伪终端将无法分配,因为标准输入不是终端。
Pseudo-terminal will not be allocated because stdin is not a terminal.
脚本片段如下,
解决方案,"to force pseudo-tty allocation even if stdin isn’t a terminal.",翻译过来,就是需要增加-t -t参数来强制伪终端分配,即使标准输入不是终端。这里非得用两个tt,表示不为这个连接分配TTY,改正片段,
关于ssh的-t参数,解释如下,
-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.
-t虚拟出一个远程服务器的终端,就是说可以提供一个远程服务器的虚拟tty终端,在多台服务器同时部署时,节省不少操作。
错误2
shell中使用FTP指令,提示错误,虽然从下载的文件来看,好像能打开,但有warning,还是不完美。
200 PORT command successful. Consider using PASV. 150 Opening BINARY mode data connection for x.log (152bytes). WARNING! 700 bare linefeeds received in ASCII mode File may not have transferred correctly.
脚本片段如下,
解决方案,就是在下载之前,先设置文件类型为binary,以二进制下载,