Macos 如何在ssh中跳过主机名并移动到下一个主机名?

Macos 如何在ssh中跳过主机名并移动到下一个主机名?,macos,bash,Macos,Bash,我有一个Bash脚本,它将基于保存主机名的.txt文件ssh到Macs中 File=/Users/<username>/Desktop/PartitionPermissions.txt echo \ >> $File cat Names.txt | xargs -I %Name ssh -n -q <username>@%Name "$(< testscript.sh)" >> $File 但是,如果其中一个主机名由于计算机当

我有一个Bash脚本,它将基于保存主机名的.txt文件ssh到Macs中

File=/Users/<username>/Desktop/PartitionPermissions.txt
echo \ >> $File
cat Names.txt | xargs -I %Name ssh -n -q <username>@%Name "$(< testscript.sh)" >>        $File

但是,如果其中一个主机名由于计算机当前未联机而无法解析,它将在此处终止脚本,而不是转到文件中的下一个主机名。有没有办法强迫它跳到下一个主机名,而不是完全停止脚本的完成?

即使ssh失败,它也应该循环并且不会失败:

File=/Users/<username>/Desktop/PartitionPermissions.txt
echo \ >> $File
while read name; do
    ssh -n -q <username>@$name "$(< testscript.sh)" >> $File
done < Names.txt
if ! ssh -n -q <username>@$name "$(< testscript.sh)" >> $File; then
    echo "ssh for $name failed"
fi