ssh到远程执行命令并返回

时间:2025-02-15 13:06:14

假设有三台机器 host1,host2,host3,host1能免密登录其他两台。要在第一台的机器里面写一个脚本分别删除每台机器的/root/test.txt

rm -rf /root/test.txt
ssh host2 <<eeooff
rm -rf /root/test.txt
exit
eeooff
ssh host3 <<eeooff
rm -rf /root/test.txt
exit
eeooff