skip to Main Content

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!

3

Answers


  1. Chosen as BEST ANSWER

    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
    

  2. 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"
    
    Login or Signup to reply.
  3. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search