当前位置: 首页 > news >正文

优化后的版本

 docker_operations.sh

#!/bin/bash# all definition
NETWORK_NAME="net-1"
VOLUME_MOUNT="-v /home/norten/Public/tools:/mnt" # 容器内部挂载到主机的路径
SCRIPT_ROUTE="/mnt" # container_run_medium.sh所在的路径
IMAGE_NAME="ubuntu"# View help command
function help_container() {echo " Usage: ./docker_operations.sh start 1 10"echo " "echo " create [num] "echo " start [start_num] [end_num] "echo " exec [start_num] [end_num] "echo " entry [num] "echo " stop [start_num] [end_num] "echo " remove [num] " echo " info [num]"echo " check [start_num] [end_num]"echo " "echo " Usage: exit "echo " exit <exit the container>"echo " docker ps  <view all running containers>"echo " docker ps -a  <view all containers>"echo " "
}# Dynamic container creation
function create_container() {echo "create zero paremeter is: $0"  echo "create first paremeter is: $1"echo "create second paremeter is: $2"  local num="$1"local CONTAINER_IP="192.168.0.$((num+60))"echo "IP IS $CONTAINER_IP"local CONTAINER_NAME="container-$num"# Check whether the IP address is already in uselocal existing_ips=($(docker inspect --format='{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq) 2>/dev/null))for ip in "${existing_ips[@]}"; doif [[ "$ip" == "$CONTAINER_IP" ]]; thenecho "Error: IP Address $CONTAINER_IP is already in use by another container."exit 1fidone  # Trying to create a containerdocker run -itd \--name "$CONTAINER_NAME" \--network="$NETWORK_NAME" \--ip="$CONTAINER_IP" \$VOLUME_MOUNT \$IMAGE_NAME \&& echo "Container $CONTAINER_NAME created with IP $CONTAINER_IP." \|| { echo "Failed to create container $CONTAINER_NAME."; exit 1; }}# Start specified or a range of containers
function start_container() {echo "start zero paremeter is: $0"  echo "start first paremeter is: $1"echo "start second paremeter is: $2"local start_num="$1"local end_num="${2:-$start_num}"  # If the second argument is not provided, it defaults to the value of the first argumentfor (( i=start_num; i<=end_num; i++ )); dolocal CONTAINER_NAME="container-$i"if docker ps -a --format '{{.Names}}' | grep -q "^$CONTAINER_NAME\$"; thenecho "Starting container $CONTAINER_NAME..."docker start "$CONTAINER_NAME"echo "Container $CONTAINER_NAME started."elseecho "Error: Container $CONTAINER_NAME does not exist."exit 1fidone
}# Stop specified or a range of containers
function stop_container() {local start_num="$1"local end_num="${2:-$start_num}"  # If the second argument is not provided, it defaults to the value of the first argumentfor (( i=start_num; i<=end_num; i++ )); dolocal CONTAINER_NAME="container-$i"if docker ps -a --format '{{.Names}}' | grep -q "^$CONTAINER_NAME\$"; thenecho "Stopping container $CONTAINER_NAME..."docker stop "$CONTAINER_NAME"echo "Container $CONTAINER_NAME stopped."elseecho "Warning: Container $CONTAINER_NAME does not exist."fidone
}# Enter the shell of a specified container or range of containers
function exec_container() {local start_num="$1"local end_num="${2:-$start_num}"  # If the second argument is not provided, it defaults to the value of the first argumentfor (( i=start_num; i<=end_num; i++ )); dolocal CONTAINER_NAME="container-$i"if docker ps -a --format '{{.Names}}' | grep -q "^$CONTAINER_NAME\$"; thenecho "Executing script in container $CONTAINER_NAME..."# Enter the container and run the scriptdocker exec -d "$CONTAINER_NAME" bash -c "cd $SCRIPT_ROUTE && ./container_run_medium.sh"echo "Script executed in container $CONTAINER_NAME."# Wait for a short time to ensure the process startssleep 2elseecho "Error: Container $CONTAINER_NAME does not exist or is not running."exit 1fidone
}# Remove a specified container
function remove_container() {local container_num="$1"local CONTAINER_NAME="container-$container_num"if docker ps -a --format '{{.Names}}' | grep -q "^$CONTAINER_NAME\$"; thenecho "Removing container $CONTAINER_NAME..."docker rm -f "$CONTAINER_NAME"echo "Container $CONTAINER_NAME removed."elseecho "Error: Container $CONTAINER_NAME does not exist."exit 1fi
}# Function to display information about a specified container
function info_container() {local container_num="$1"if ! [[ "$container_num" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: The number must be an integer between 1 and 1000."return 1filocal CONTAINER_NAME="container-$container_num"# Check if the container existsif docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null | grep -q 'true'; thenecho "Information for container $CONTAINER_NAME:"docker inspect "$CONTAINER_NAME"elseecho "Error: Container $CONTAINER_NAME does not exist or is not running."fi
}# Check if the script is running in a specified container or range of containers
function check_script_running() {local start_num="$1"local end_num="${2:-$start_num}"  # If the second argument is not provided, it defaults to the value of the first argumentfor (( i=start_num; i<=end_num; i++ )); dolocal CONTAINER_NAME="container-$i"# Check if the container exists and is runningif docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null | grep -q 'true'; thenecho "Container $CONTAINER_NAME is running."# Check if MediumBoxBase is running using pgrepif docker exec -it "$CONTAINER_NAME" pgrep -f 'MediumBoxBase' > /dev/null; thenecho "Script is running in container $CONTAINER_NAME."elseecho "Error: Script is not running in container $CONTAINER_NAME."fielseecho "Error: Container $CONTAINER_NAME does not exist or is not running."fi# Add a newline for separationechodone# Ensure the terminal ends with a newlineecho
}# Function to enter a specified container
function entry_container() {local container_num="$1"if ! [[ "$container_num" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: The number must be an integer between 1 and 1000."return 1filocal CONTAINER_NAME="container-$container_num"# Check if the container exists and is runningif docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null | grep -q 'true'; thenecho "Entering container $CONTAINER_NAME..."docker exec -it "$CONTAINER_NAME" bashelseecho "Error: Container $CONTAINER_NAME does not exist or is not running."fi
}case "$1" inhelp)help_container;;create)if [ "$#" -ne 2 ]; thenecho "Error: You should provide a parameter after 'create'."exit 1fiif ! [[ "$2" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: The number must be an integer between 1 and 1000."exit 1ficreate_container "$2";;start)# Check the number of parameters to determine whether to start a single container or a container rangeif [ "$#" -lt 2 ]; thenecho "Error: You should provide at least one number after 'start'."exit 1elif [ "$#" -eq 2 ]; then# If there are only two parameters, try starting a containerstart_container "$2"elif [ "$#" -eq 3 ]; then# If you have three parameters, try starting a series of containersif ! [[ "$2" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]] || ! [[ "$3" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: Both numbers must be integers between 1 and 1000."exit 1fiif [ "$2" -gt "$3" ]; thenecho "Error: The first number must be less than or equal to the second."exit 1fistart_container "$2" "$3"elseecho "Error: Too many arguments for 'start'."exit 1fi;;stop)if [ "$#" -lt 2 ]; thenecho "Error: You should provide at least one number after 'stop'."exit 1fiif ! [[ "$2" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: The number(s) must be integers between 1 and 1000."exit 1fiif [ "$#" -eq 2 ]; thenstop_container "$2"elif [ "$#" -eq 3 ]; thenif ! [[ "$3" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: Both numbers must be integers between 1 and 1000."exit 1fiif [ "$2" -gt "$3" ]; thenecho "Error: The second number must be greater than or equal to the first."exit 1fistop_container "$2" "$3"elseecho "Error: Too many arguments for 'stop'."exit 1fi;;exec)if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; thenecho "Error: You should provide one or two numbers after 'exec'."exit 1fiif ! [[ "$2" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: The number(s) must be integers between 1 and 1000."exit 1fiif [ "$#" -eq 2 ]; thenexec_container "$2"elif [ "$#" -eq 3 ]; thenif ! [[ "$3" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: Both numbers must be integers between 1 and 1000."exit 1fiif [ "$2" -gt "$3" ]; thenecho "Error: The first number must be less than or equal to the second."exit 1fiexec_container "$2" "$3"fi;;check)if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; thenecho "Error: You should provide one or two numbers after 'check'."exit 1fiif ! [[ "$2" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: The number(s) must be integers between 1 and 1000."exit 1fiif [ "$#" -eq 2 ]; thencheck_script_running "$2"elif [ "$#" -eq 3 ]; thenif ! [[ "$3" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: Both numbers must be integers between 1 and 1000."exit 1fiif [ "$2" -gt "$3" ]; thenecho "Error: The first number must be less than or equal to the second."exit 1ficheck_script_running "$2" "$3"fi# Reset the terminal to ensure normal behaviorstty sane;;entry)if [ "$#" -ne 2 ]; thenecho "Error: You should provide exactly one number after 'entry'."exit 1fiif ! [[ "$2" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: The number must be an integer between 1 and 1000."exit 1fientry_container "$2";;remove)if [ "$#" -ne 2 ]; thenecho "Error: You should provide exactly one number after 'remove'."exit 1fiif ! [[ "$2" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: The number must be an integer between 1 and 1000."exit 1firemove_container "$2";;info)if [ "$#" -ne 2 ]; thenecho "Error: You should provide exactly one number after 'info'."exit 1fiif ! [[ "$2" =~ ^[1-9][0-9]{0,2}|[1-9][0-9]{3}$ ]]; thenecho "Error: The number must be an integer between 1 and 1000."exit 1fiinfo_container "$2";;logs|status)echo "Function '$1' has not been updated to handle numbered containers."exit 1;;*)echo "Invalid command. Use './docker_operations.sh help' to get instructions."exit 1;;
esacexit 0

./mnt/container_run_medium.sh

#!/bin/bash# 清理旧的日志文件
rm -f *.log
rm -f nohup.out
rm -f cssd.dat# 启动 pwbox_simu 和 MediumBoxBase
nohup /mnt/simutools/pwbox_simu /mnt/simutools/pw_box.conf > /dev/null 2>&1 &
nohup /mnt/mediumSimu/MediumBoxBase /mnt/mediumSimu/hynn_flash_config_simu.conf > /dev/null 2>&1 &

相关文章:

优化后的版本

docker_operations.sh #!/bin/bash# all definition NETWORK_NAME"net-1" VOLUME_MOUNT"-v /home/norten/Public/tools:/mnt" # 容器内部挂载到主机的路径 SCRIPT_ROUTE"/mnt" # container_run_medium.sh所在的路径 IMAGE_NAME"ubuntu&quo…...

【Linux系统编程】第二十七弹---文件描述符与重定向:fd奥秘、dup2应用与Shell重定向实战

✨个人主页&#xff1a; 熬夜学编程的小林 &#x1f497;系列专栏&#xff1a; 【C语言详解】 【数据结构详解】【C详解】【Linux系统编程】 目录 1、文件描述符fd 1.1、0 & 1 & 2 1.2、文件描述符的分配规则 2、重定向 3、使用 dup2 系统调用 3.1、> 输出…...

开放式耳机哪个品牌好?好用且高性价比的开放式蓝牙耳机推荐

相信很多经常运动的朋友都不是很喜欢佩戴入耳式耳机&#xff0c;因为入耳式耳机真的有很多缺点。 安全方面&#xff1a;在安全上就很容易存在隐患&#xff0c;戴上后难以听到周围环境声音&#xff0c;像汽车鸣笛、行人呼喊等&#xff0c;容易在运动中发生意外。 健康方面&…...

区间合并——模板题

题目描述 给定 n 个区间 [li, ri]&#xff0c;要求合并所有有交集的区间。注意如果在端点处相交&#xff0c;也算有交集。 输出合并完成后的区间个数。 例如&#xff1a;[1, 3] 和 [2, 6] 可以合并为一个区间 [1, 6]。 输入格式 第一行包含整数 n 。 接下来 n 行&#xff0c…...

Microsoft Edge 五个好用的插件

&#x1f423;个人主页 可惜已不在 &#x1f424;这篇在这个专栏 插件_可惜已不在的博客-CSDN博客 &#x1f425;有用的话就留下一个三连吧&#x1f63c; 目录 Microsoft Edge 一.安装游览器 ​编辑 二.找到插件商店 1.打开游览器后&#xff0c;点击右上角的设置&#…...

解决 遇到JWT中claims中获取不到数据的问题

1.先介绍一下JWT的常规流程 用户进行登录将token储存到redis&#xff0c;然后进行其他需要验证的操作时进行验证&#xff0c;比如使用拦截器进行验证&#xff0c;那么id存储的到claims&#xff0c;因为可以在拦截器验证时将其存放到ThreadLocal中&#xff0c;这样通过ThreadLo…...

会议平台后端优化方案

会议平台后端优化方案 通过RTC的学习&#xff0c;我了解到了端对端技术&#xff0c;就想着做一个节省服务器资源的会议平台 之前做了这个项目&#xff0c;快手二面被问到卡着不知如何介绍&#xff0c;便有了这篇文章 分析当下机制 相对于传统视频平台&#xff08;SFU&#xff…...

unixODBC编程(十)分片插入长数据

遇到有LONG数据类型的表&#xff0c;要插入一条数据量很大的行&#xff0c;一次插入的缓冲区会不够大&#xff0c;这时需要一部分一部分的插入LONG数据&#xff0c;这就用到了在执行语句时动态提供数据的机制。在ODBC中要动态提供数据需要几个步骤。 1. 在绑定输入参数时&…...

【Java】—— 集合框架:Collection子接口:Set不同实现类的对比及使用(HashSet、LinkedHashSet、TreeSet)

目录 5. Collection子接口2&#xff1a;Set 5.1 Set接口概述 5.2 Set主要实现类&#xff1a;HashSet 5.2.1 HashSet概述 5.2.2 HashSet中添加元素的过程&#xff1a; 5.2.3 重写 hashCode() 方法的基本原则 5.2.4 重写equals()方法的基本原则 5.2.5 练习 5.3 Set实现类…...

android Activity生命周期

android 中一个 activity 在其生命周期中会经历多种状态。 您可以使用一系列回调来处理状态之间的转换。下面我们来介绍这些回调。 onCreate&#xff08;创建阶段&#xff09; 初始化组件&#xff1a;在这个阶段&#xff0c;Activity的主要工作是进行初始化操作。这包括为Ac…...

C#的面向对象

1&#xff09;对象 算法数据结构 2&#xff09;对象的行为已方法的形式定义的&#xff0c;属性以成员变量的形式定义的 面向对象程序设计的特点 1&#xff09;封装性 2&#xff09;继承性 3&#xff09;多态性 知识点&#xff1a; 封装性面向对象的核心思想&#xff0c;将…...

【区别】三种命令取消已暂存的文件,处理暂存区和文件的跟踪状态

取消已暂存的文件 git restore --staged <文件>、git reset HEAD <文件> 和 git rm --cached <文件> 都可以用于取消已暂存的文件&#xff0c;但它们的作用和使用场景略有不同。下面是它们的区别&#xff1a; 1. git restore --staged <文件> 该命令…...

如何在Spring Boot中有条件地运行CommandLineRunner Bean

PS 使用 Spring Boot 3.1.2 进行测试 1.使用ConditionalOnProperty ConditionalOnProperty仅当特定属性存在或具有特定值时&#xff0c;注释才会创建 Bean 。 在此示例中&#xff0c;仅当或文件中的CommandLineRunner属性db.init.enabled设置为 true时&#xff0c;才会执行。…...

边缘自适应粒子滤波(Edge-Adaptive Particle Filter)的MATLAB函数示例,以及相应的讲解

目录 讲解 初始化 预测步骤 观测模拟 权重更新 重采样 状态估计 总结 下面是一个简单的边缘自适应粒子滤波&#xff08;&#xff09;的函数示例&#xff0c;以及相应的讲解。 程序源代码&#xff1a; function X_est edgeAdaptiveParticleFilter(numParticles, numS…...

一块1T硬盘怎么有sdb1和sdb2

在一块 1TB 硬盘上看到两个分区 sdb1 和 sdb2 是非常常见的现象。硬盘可以被划分为多个分区&#xff0c;每个分区都可以用作不同的目的&#xff0c;如存储不同类型的数据、安装不同的操作系统或为系统不同的功能提供支持。 1. 分区的概念 硬盘可以被划分为多个分区&#xff0…...

Python知识点:如何使用Flink与Python进行实时数据处理

开篇&#xff0c;先说一个好消息&#xff0c;截止到2025年1月1日前&#xff0c;翻到文末找到我&#xff0c;赠送定制版的开题报告和任务书&#xff0c;先到先得&#xff01;过期不候&#xff01; 如何使用Flink与Python进行实时数据处理 Apache Flink是一个流处理框架&#xf…...

Swagger配置且添加小锁(asp.net)(笔记)

此博客是基于 asp.net core web api(.net core3.1)框架进行操作的。 一、安装Swagger包 在 NuGet程序包管理中安装下面的两个包&#xff1a; swagger包&#xff1a;Swashbuckle.AspNetCore swagger包过滤器&#xff1a;Swashbuckle.AspNetCore.Filters 二、swagger注册 在…...

lambda表达式底层实现:反编译LambdaMetafactory + 转储dump + 运行过程 + 反汇编 + 动态指令invokedynamic

一、结论先行 lambda 底层实现机制 1.lambda 表达式的本质&#xff1a;函数式接口的匿名子类的匿名对象 2.lambda表达式是语法糖 语法糖&#xff1a;编码时是lambda简洁的表达式&#xff0c;在字节码期&#xff0c;语法糖会被转换为实际复杂的实现方式&#xff0c;含义不变&am…...

Unity初识+面板介绍

Unity版本使用 小版本号高&#xff0c;出现bug可能性更小&#xff1b;一台电脑可以安装多个版本的Unity&#xff0c;但是需要安装在不同路径&#xff1b;安装Unity时不能有中文路径&#xff1b;Unity项目路径也不要有中文。 Scene面板 相当于拍电影的片场&#xff0c;Unity程…...

【CSS in Depth 2 精译_041】6.4 CSS 中的堆叠上下文与 z-index(上)

当前内容所在位置&#xff08;可进入专栏查看其他译好的章节内容&#xff09; 第一章 层叠、优先级与继承&#xff08;已完结&#xff09;第二章 相对单位&#xff08;已完结&#xff09;第三章 文档流与盒模型&#xff08;已完结&#xff09;第四章 Flexbox 布局&#xff08;已…...

基于LSTM的无人艇波浪方向估计:从时序预测到工程实践

1. 项目概述&#xff1a;当无人艇“学会”感知海浪在海洋工程和无人系统领域&#xff0c;让机器“感知”并“理解”它所处的海洋环境&#xff0c;尤其是波浪的动态特性&#xff0c;一直是个核心挑战。想象一下&#xff0c;你驾驶一艘小船&#xff0c;如果能提前几秒甚至更久“预…...

Frida免Root模拟Xposed模块:原理、映射与工业级实践

1. 这不是“替代”&#xff0c;而是“重写”&#xff1a;为什么Frida能跑出Xposed的效果&#xff0c;却根本不需要Root“Frida vs Xposed”这个标题常被误读成一场工具对决——仿佛两者是同一赛道上的竞品&#xff0c;只待用户选边站队。但实操十年下来&#xff0c;我越来越确信…...

2025亲测好用的论文降AI工具,降重稳还不打乱原格式

说真的&#xff0c;现在写论文最慌的已经不是重复率飘红&#xff0c;而是AI检测率超标。尤其是用过AI辅助写作或者改写的同学&#xff0c;检测报告一出来AI率直奔80%&#xff0c;导师一句“这是你自己写的&#xff1f;”就能让人瞬间心脏骤停。 我最近花了一周时间&#xff0c;…...

消费电子贴膜的光学技术革新:圆偏振光与磁控溅射AR的原理解析

摘要随着用户对屏幕使用健康关注的提升&#xff0c;消费电子贴膜行业正在经历从“物理防护”到“光学级视觉守护”的技术升级。本文从光学原理出发&#xff0c;解析圆偏振光柔光标准与磁控溅射AR抗眩镀膜两项核心技术的工作机制&#xff0c;并分析其在屏幕保护场景中的应用逻辑…...

Linux ln 软硬链接详解——底层原理+生产实战+彻底区分(零踩坑)

前言很多新手永远分不清软硬链接&#xff0c;只会背“软链接像快捷方式、硬链接像副本”&#xff0c;一旦遇到生产删文件、日志切割、程序部署就翻车。本文从inode底层原理讲起&#xff0c;配合完整实战、对比、生产场景&#xff0c;让你彻底吃透 ln 软硬链接&#xff0c;面试、…...

2026年HR推荐的10个专业简历模板网站,从模板到写法

2026年HR推荐的10个专业简历模板网站&#xff0c;从模板到写法写一份让HR眼前一亮的简历&#xff0c;是很多求职者遇到的难题。模板选什么风格、内容怎么写才专业、怎么排版才不会被系统筛掉——这些问题常常让人头疼。这篇文章整理了10个HR推荐的专业简历模板网站&#xff0c;…...

eLabFTW深度解析:开源电子实验记录本的技术架构与实战应用

eLabFTW深度解析&#xff1a;开源电子实验记录本的技术架构与实战应用 【免费下载链接】elabftw :notebook: eLabFTW is the most popular open source electronic lab notebook for research labs. 项目地址: https://gitcode.com/gh_mirrors/el/elabftw eLabFTW作为最…...

大模型的伦理与合规:隐私保护、偏见与安全问题

在大模型技术深度渗透各行业的当下&#xff0c;软件测试从业者正站在保障AI技术负责任发展的关键节点。从医疗诊断辅助系统到金融风控模型&#xff0c;大模型的每一次输出都关乎用户权益与社会公平。作为质量把关人&#xff0c;测试从业者需突破传统软件测试边界&#xff0c;构…...

taotoken如何帮助初创团队以可控成本快速验证ai产品创意

&#x1f680; 告别海外账号与网络限制&#xff01;稳定直连全球优质大模型&#xff0c;限时半价接入中。 &#x1f449; 点击领取海量免费额度 Taotoken如何帮助初创团队以可控成本快速验证AI产品创意 1. 初创团队验证AI创意的核心挑战 对于初创团队而言&#xff0c;验证一个…...

照着用就行:盘点2026年顶尖配置的的降AIGC软件

轻松降低论文AI率在2026年已不再是天方夜谭。最新一代降AIGC软件强势来袭&#xff0c;覆盖AI痕迹消除、文本改写润色、降重优化、学术合规检测四大核心场景&#xff0c;实测提速明显&#xff0c;高效解决论文AI痕迹难题。 一、全流程王者&#xff1a;一站式搞定论文全链路 这类…...