why the "test.log" is empty?
The logs of shellscript seems to return on the terminal directly.
How can I record the returns of ssh-command ito a logfile in the script?
Not sh while.sh &> test.log
Thanks for your help ! ^_^
root@jump:~/sshtest# cat nodes
172.25.16.8
172.25.16.7
172.25.16.135
172.25.16.104
172.25.16.103
root@jump:~/sshtest# cat while.sh
#!/bin/bash
#set -x
exec &> test.log
nodes=nodes
while read node
do
echo "---- $node ----"
ssh $node hostname </dev/null
done < $nodes
root@jump:~/sshtest# sh while.sh
---- 172.25.16.8 ----
prometheus-vm2
---- 172.25.16.7 ----
prometheus-vm1
---- 172.25.16.135 ----
operator-vm6
---- 172.25.16.104 ----
operator-vm5
---- 172.25.16.103 ----
operator-vm4
root@jump:~/sshtest# ls -l test.log
-rw-r--r-- 1 root root 0 2021-08-09 14:55:49 test.log
root@jump:~/sshtest# uname -a
Linux jump 4.9.0-11-amd64 #1 SMP Debian 4.9.189-3+deb9u1 (2019-09-20) x86_64 GNU/Linux