0

I am in need of installing elasticstack on multiple systems currently and would like to invoke this via bash script. Two of the steps to installing elasticsearch is to add the GPG Key and then create a sources.list file for the repository.

When running this manually in terminal these commands are piped as follows:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list

when attempting to create the script for this action it seems to just hang. I am assuming that this is due to the command pipes. So my question would be how can I add these lines into a bash script so that I am able to run this without any issue?

dessert
  • 39,982
robz
  • 3

1 Answers1

0

sudo is a command one normally doesn’t use in scripts (see How do I run a 'sudo' command inside a script?), you rather run the whole script as root. Your script would then be

#!/bin/bash
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" >>/etc/apt/sources.list.d/elastic-6.x.list

and you should make it executable with chmod +x /path/to/script and run it with:

sudo /path/to/script
dessert
  • 39,982