Here's what I want to do.I want to check over 100 hosts and see if a file exists on that host. If the file does exist, then I want to print the hostname and the output of the command.In this example example, assume that I have three hosts: host1.example.org host2.example.org host3.example.org . The file /etc/foobar exists on host2.example.org, but not on host1.example.org or host3.example.org .I want to run ls -l /etc/foobar on each host in the list.If this file exists on that host, then print the hostname and the output of the command.If the file does not exist on that host, then don't print anything. I don't want the extra noise. HOSTLIST=host1.example.org host2.example.org host3.example.orgfor HOST in $HOSTLISTdo    echo ### $HOST    ssh $HOST ls -ld /etc/foobardoneIdeal output would be:### host2.example.orgdrwx------ 3 root root 4096 Apr 10 16:57 /etc/foobarBut the actual output is:### host1.example.org### host2.example.orgdrwx------ 3 root root 4096 Apr 10 16:57 /etc/foobar### host3.example.orgI don't want the lines for host1.example.org or host3.example.org to print.I am experimenting braces to contain the output spit out by echo and ssh, but I can't figure out the magic syntax to do what I want. I am sure that I have done this in the past without control characters, HOSTLIST=host1.example.org host2.example.org host3.example.orgfor HOST in $HOSTLISTdo    # If 'ls' shows nothing, don't print $HOST or output of command    # This doesn't work    { echo ### $HOST && ssh $HOST ls -ld /etc/foobar ; } 2>/dev/nulldone
Execute a command on multiple hosts, but only print command if it is successful?
ssh;shell script;remote management