Skip to main content

sudo redirect to a file

When wanting to append some string to a file using sudo

[mihamina@dell-f17 ~]$ pdsh  'echo "sshd:LOCAL,41.190.237.66,41.188.46.121" | sudo tee  /etc/hosts.allow'
hosting: sshd:LOCAL,41.190.237.66,41.188.46.121
filer: sshd:LOCAL,41.190.237.66,41.188.46.121
recette53: sshd:LOCAL,41.190.237.66,41.188.46.121
prod53: sshd:LOCAL,41.190.237.66,41.188.46.121
recette52: sshd:LOCAL,41.190.237.66,41.188.46.121
prod52: sshd:LOCAL,41.190.237.66,41.188.46.121

And it gives:

[mihamina@dell-f17 ~]$ pdsh  'sudo grep sshd /etc/hosts.allow'
recette53: sshd:LOCAL,41.190.237.66,41.188.46.121
prod53: sshd:LOCAL,41.190.237.66,41.188.46.121
filer: sshd:LOCAL,41.190.237.66,41.188.46.121
hosting: sshd:LOCAL,41.190.237.66,41.188.46.121
recette52: sshd:LOCAL,41.190.237.66,41.188.46.121
prod52: sshd:LOCAL,41.190.237.66,41.188.46.121