0

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:

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!

bbartling
  • 3,288
  • 9
  • 43
  • 88

3 Answers3

0

In terminal run $ bash make_reg_configs.sh 11

#! /bin/bash

vctl config store platform.driver registry_configs/$1.csv ./registry_configs/$1.csv --csv
vctl config store platform.driver devices/slipstream_internal/slipstream_hq/$1 ./devices/$1
bbartling
  • 3,288
  • 9
  • 43
  • 88
0

Perhaps you're wanting to have a convenient method of sending commands to screen while also executing them in obe call. You can create a convenient function for that.

function call {
    printf '%q ' "$@" # Prints args separately while also properly escaped to show which spaces are part of an argument
    echo # Add newline
    "$@" # Execute command
}

call vctl config store platform.driver "registry_configs/$1.csv" "./registry_configs/$1.csv" --csv
call vctl config store platform.driver "devices/slipstream_internal/slipstream_hq/$1" "./devices/$1"
konsolebox
  • 72,135
  • 12
  • 99
  • 105
  • Could you ever look at my answer which works...but ideally is it possible to include for loop with BASH and loop through a data structure of `addresses`? – bbartling Feb 04 '23 at 20:31
  • @bbartling Tink just gave an [answer](https://stackoverflow.com/a/75348196/445221) for that. Is it what you want? – konsolebox Feb 04 '23 at 20:44
0

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
konsolebox
  • 72,135
  • 12
  • 99
  • 105
tink
  • 14,342
  • 4
  • 46
  • 50
  • Thanks...what type of file extension should I save for `addresses` like a .json, .txt, or .csv? Sorry not a lot of wisdom here... – bbartling Feb 04 '23 at 20:49
  • Linux doesn't need extensions at all (well, most programs don't) ... for your own sake you might call it `.lst` or `.txt`. Btw, giving a shell-script an extension is largely considered bad practice, more so when you use `bash` but name it `sh`. @bbartling – tink Feb 04 '23 at 21:09
  • P.S.: Thanks for the cleanup @konsolebox ... given the data I figured I could do without the quotes. In general it's of course much cleaner and safer to quote shell variables. – tink Feb 04 '23 at 21:11