Both of these commands work: (note the -S
in sudo
tells sudo to read the password from stdin).
echo 'mypassword' | sudo -S tee -a /etc/test.txt &> /dev/null
echo -e '\nsome\nmore\ntext' | sudo tee -a /etc/test.txt &> /dev/null
Now I would like to combine the two, i.e. achieve everything in just one line. But, of course, something like this doesn't work:
echo -e '\nsome\nmore\ntext' | echo 'mypassword' | sudo -S tee -a /etc/test.txt &> /dev/null
What would work? Thanks:) - Loady
PS: Minor unrelated question: is 1> identical to > ? I believe they are..
NOPASSWD
entry to yoursudoers
file? – Martin von Wittich Sep 12 '17 at 17:23sudo
from a script or a cronjob or something, so that it has to run non-interactively? Then theNOPASSWD
option is probably far safer and less complicated than putting the password into a script and trying to pipe it intosudo
. – Martin von Wittich Sep 13 '17 at 15:29