Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Enter in information into terminal with BASH

I am working on trying to configure a Python based IoT platform on a Ubuntu 20.04 LTS edge device that requires a lot of redundant steps for entering information into the terminal.

For example I have to run these two commands below inside a Python virtual environment for device address number where I am showing device address number 11 as an example:

(volttron) geb@volttron:~$vctl config store platform.driver registry_configs/11.csv ./registry_configs/11.csv --csv
(volttron) geb@volttron:~$vctl config store platform.driver devices/slipstream_internal/slipstream_hq/11 ./devices/11

And I have all these device addresses to do the same command but switch out the 11 for the correct address:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

12035
15
21
25
30
36
4
5233
5237
5241
73017
9
1002
12028
12
16
22
26
31
37
5230
5234
5238
5242
73018
10
12032
13
19
23
27
33333
38
5231
5235
5239
6
7
1100
12033
14
20
24
29
34
39
5232
5236
5240
73005
8

I’m a first timer in Bash … so I started this journey with: $ nano make_reg_configs.sh

And it looks like this:

#! /bin/bash

echo "vctl config store platform.driver registry_configs/$1.csv ./registry_configs/$1.csv --csv"
echo "vctl config store platform.driver devices/slipstream_internal/slipstream_hq/$1 ./devices/$1"

So at least with this I think I can just do below for each one of my addresses:
bash make_reg_configs.sh "11"

That returns:

vctl config store platform.driver registry_configs/11.csv ./registry_configs/11.csv --csv
vctl config store platform.driver devices/slipstream_internal/slipstream_hq/11 ./devices/11

Where it looks correct with just printing the string with echo but how would I enter the string into the terminal? I think I need something other than echo, would also be cool to just for loop through all the addresses as well if its not a hassle to incorporate that as well. Hopefully this all makes sense!

>Solution :

And if I understood your final goal correctly (combining with the comment from diego)… if you save your addresses to a file called addresses in the same directory as your script this would do them all:

#! /bin/bash
while read address
do
  vctl config store platform.driver "registry_configs/${address}.csv" "./registry_configs/${address}.csv" --csv
  vctl config store platform.driver "devices/slipstream_internal/slipstream_hq/${address}" "./devices/${address}"
done<addresses
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading