You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 20.04下Bash批量执行Volttron设备配置命令需求

批量配置Volttron设备的Bash脚本解决方案

以下是修改后的make_reg_configs.sh脚本,可直接批量执行设备配置命令,同时加入错误检查和状态提示:

#!/bin/bash

# 定义需要处理的设备地址列表,按需添加/修改ID
DEVICE_IDS=(11 12 13 14)

# 遍历每个设备地址执行配置
for id in "${DEVICE_IDS[@]}"
do
    echo "=== 开始处理设备地址: $id ==="
    
    # 执行第一条注册表配置命令
    vctl config store platform.driver registry_configs/"$id".csv ./registry_configs/"$id".csv --csv
    
    # 检查命令执行状态,失败则跳过当前设备后续操作
    if [ $? -ne 0 ]; then
        echo "❌ 设备 $id 注册表配置失败,跳过设备配置"
        continue
    fi
    
    # 执行第二条设备映射配置命令
    vctl config store platform.driver devices/slipstream_internal/slipstream_hq/"$id" ./devices/"$id"
    
    # 反馈最终结果
    if [ $? -eq 0 ]; then
        echo "✅ 设备 $id 配置完成"
    else
        echo "❌ 设备 $id 映射配置失败"
    fi
done

echo "=== 所有设备配置处理结束 ==="

使用说明

  1. 激活Volttron虚拟环境:运行脚本前确保已进入虚拟环境,例如:
    source volttron/env/bin/activate
    
  2. 修改设备列表:根据实际需求编辑DEVICE_IDS数组,添加所有需要配置的设备地址。
  3. 赋予执行权限:
    chmod +x make_reg_configs.sh
    
  4. 运行脚本:
    ./make_reg_configs.sh
    

可选优化:从文件读取设备ID

如果设备地址较多,可将ID存入ids.txt文件(每行一个ID),使用以下脚本批量读取:

#!/bin/bash

# 从ids.txt读取设备地址,跳过空行和注释行(#开头)
while read -r id
do
    [[ -z "$id" || "$id" =~ ^# ]] && continue
    
    echo "=== 开始处理设备地址: $id ==="
    
    vctl config store platform.driver registry_configs/"$id".csv ./registry_configs/"$id".csv --csv
    
    if [ $? -ne 0 ]; then
        echo "❌ 设备 $id 注册表配置失败,跳过设备配置"
        continue
    fi
    
    vctl config store platform.driver devices/slipstream_internal/slipstream_hq/"$id" ./devices/"$id"
    
    if [ $? -eq 0 ]; then
        echo "✅ 设备 $id 配置完成"
    else
        echo "❌ 设备 $id 映射配置失败"
    fi
done < ids.txt

echo "=== 所有设备配置处理结束 ==="

内容的提问来源于stack exchange,提问作者bbartling

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 15:00:49