以下是我的脚本的一部分,echo
如果 ssh 中的条件失败,我希望将一些文本发送到本地终端。
/usr/bin/sshpass -p $PASSWORD /usr/bin/ssh -t -o "StrictHostKeyChecking no" root@$IP -p $PORT '
cd $PATH;
[ ! -d temp ] && mkdir temp;
for new_file in '${NEW_FILE[@]}'
do
[ -f $new_file ] && mv -f $new_file temp/$new_file-'$DATE'
DOWNLOAD=$(wget --no-check-certificate '$URL'/$new_file > /dev/null 2>&1)
if [ '$?' -ne '0' ]; then
mv temp/$new_file-'$DATE' '$PATH'/$new_file
echo "$new_file download failed! please check and re-run the script"
else
chmod +x $new_file
fi
done;'
除了echo
其余功能运行良好......
让我知道是否可以echo
从ssh
本地终端出发。
答案1
要有选择地显示单个命令及其输出,您可以使用类似
sh -vc 'echo \"Some text\"'
尽管嵌套引用很快就会让你感到不安。
答案2
ssh -t
从手册页:
-t Force pseudo-terminal 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.