-1

My command is

echo "deb http://www.apache.org/dist/cassandra/debian 311x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list

I want to pass my password user-password as an argument in the above command similar to the one shown below:

echo user-password | sudo -S apt-get update

My issue is that i don't know how to pass both the URL as well as the sudo password simultaneously.

Also i am ensuring that the password is not visible on the terminal as this command will be called by a python script which reads the password from a file (or from user)

AksTester
  • 117

1 Answers1

1

Shuffle the command a bit, moving the echo for the source inside the sudo command:

echo password | sudo -S sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" >> /etc/apt/sources.list.d/cassandra.sources.list' 
muru
  • 207,228