我尝试按顺序通过 SSH 访问一组主机,并运行命令以获取每个主机上的用户列表。在 for 循环之外,输出会逐个显示。在 for 循环内部,它会消失。如何使该输出可见?
#!/bin/bash
#grab a bunch of IP addresses from a file
for address in $(cat ip_list.txt)
do
#output for this shows up.
echo "connecting to $address";
#output for this does not
sshpass -p 'password' ssh account@$address "echo $address;dscl . list /Users | grep -v '^_\|nobody\|daemon\|admin\|root'; exit"
done