优化后的版本
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重定向实战
✨个人主页: 熬夜学编程的小林 💗系列专栏: 【C语言详解】 【数据结构详解】【C详解】【Linux系统编程】 目录 1、文件描述符fd 1.1、0 & 1 & 2 1.2、文件描述符的分配规则 2、重定向 3、使用 dup2 系统调用 3.1、> 输出…...

开放式耳机哪个品牌好?好用且高性价比的开放式蓝牙耳机推荐
相信很多经常运动的朋友都不是很喜欢佩戴入耳式耳机,因为入耳式耳机真的有很多缺点。 安全方面:在安全上就很容易存在隐患,戴上后难以听到周围环境声音,像汽车鸣笛、行人呼喊等,容易在运动中发生意外。 健康方面&…...

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

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

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

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

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

【Java】—— 集合框架:Collection子接口:Set不同实现类的对比及使用(HashSet、LinkedHashSet、TreeSet)
目录 5. Collection子接口2:Set 5.1 Set接口概述 5.2 Set主要实现类:HashSet 5.2.1 HashSet概述 5.2.2 HashSet中添加元素的过程: 5.2.3 重写 hashCode() 方法的基本原则 5.2.4 重写equals()方法的基本原则 5.2.5 练习 5.3 Set实现类…...

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

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

【区别】三种命令取消已暂存的文件,处理暂存区和文件的跟踪状态
取消已暂存的文件 git restore --staged <文件>、git reset HEAD <文件> 和 git rm --cached <文件> 都可以用于取消已暂存的文件,但它们的作用和使用场景略有不同。下面是它们的区别: 1. git restore --staged <文件> 该命令…...

如何在Spring Boot中有条件地运行CommandLineRunner Bean
PS 使用 Spring Boot 3.1.2 进行测试 1.使用ConditionalOnProperty ConditionalOnProperty仅当特定属性存在或具有特定值时,注释才会创建 Bean 。 在此示例中,仅当或文件中的CommandLineRunner属性db.init.enabled设置为 true时,才会执行。…...
边缘自适应粒子滤波(Edge-Adaptive Particle Filter)的MATLAB函数示例,以及相应的讲解
目录 讲解 初始化 预测步骤 观测模拟 权重更新 重采样 状态估计 总结 下面是一个简单的边缘自适应粒子滤波()的函数示例,以及相应的讲解。 程序源代码: function X_est edgeAdaptiveParticleFilter(numParticles, numS…...

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

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

Swagger配置且添加小锁(asp.net)(笔记)
此博客是基于 asp.net core web api(.net core3.1)框架进行操作的。 一、安装Swagger包 在 NuGet程序包管理中安装下面的两个包: swagger包:Swashbuckle.AspNetCore swagger包过滤器:Swashbuckle.AspNetCore.Filters 二、swagger注册 在…...

lambda表达式底层实现:反编译LambdaMetafactory + 转储dump + 运行过程 + 反汇编 + 动态指令invokedynamic
一、结论先行 lambda 底层实现机制 1.lambda 表达式的本质:函数式接口的匿名子类的匿名对象 2.lambda表达式是语法糖 语法糖:编码时是lambda简洁的表达式,在字节码期,语法糖会被转换为实际复杂的实现方式,含义不变&am…...

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

【CSS in Depth 2 精译_041】6.4 CSS 中的堆叠上下文与 z-index(上)
当前内容所在位置(可进入专栏查看其他译好的章节内容) 第一章 层叠、优先级与继承(已完结)第二章 相对单位(已完结)第三章 文档流与盒模型(已完结)第四章 Flexbox 布局(已…...

uniapp微信小程序巧用跳转封装鉴权路由
1.这是封装的跳转方法: import store from "../stores/store";function Router(type, url, params) {const NoLoginPage [。。。。。];var queryString Object.keys(params).map((key) > ${key}${params[key]}).join("&");if (!NoLog…...

国外电商系统开发-运维系统开发
因项目运营环境在国外,所以必须将服务器选择国外,加上第一次运营国外项目。在两大趋势下,企业的运营方向必须通过大数据来分析及修正运营方向,加上后期服务器数量日益增多,如何有效的管理众多的服务器及验证运营方向&a…...

基于投影滤波算法的rick合成地震波滤波matlab仿真
目录 1.课题概述 2.系统仿真结果 3.核心程序与模型 4.系统原理简介 4.1 RICK合成地震波模型 4.2 投影滤波算法原理 5.完整工程文件 1.课题概述 基于投影滤波算法的rick合成地震波滤波matlab仿真。分别通过标准的滤波投影滤波以及卷积滤波投影滤波对合成地震剖面进行滤波…...

【艾思科蓝】机器学习框架终极指南:PyTorch vs TensorFlow vs Keras vs Scikit-learn
第十届建筑、土木与水利工程国际学术会议(ICACHE 2024)_艾思科蓝_学术一站式服务平台 更多学术会议请看:学术会议-学术交流征稿-学术会议在线-艾思科蓝 目录 引言 1. PyTorch PyTorch的特点 PyTorch的用例 PyTorch的安装 PyTorch代码示例 2. TensorFlow …...

招联金融秋招内推2025
【投递方式】 直接扫下方二维码,或点击内推官网https://wecruit.hotjob.cn/SU61025e262f9d247b98e0a2c2/mc/position/campus,使用内推码 igcefb 投递) 【招聘岗位】 后台开发 前端开发 数据开发 数据运营 算法开发 技术运维 软件测试 产品策…...

遮罩解决图片悬浮操作看不到的情况
未悬浮效果 悬浮效果 如果仅仅是添加绝对定位,那么遇到白色图片,就会看不到白色字体。通过遮罩(绝对定位透明度)就可以解决这个问题。 <script setup> </script><template><div class"box"><…...

IoT网关的主要功能有哪些?天拓四方
在数字化浪潮席卷全球的今天,物联网(IoT)技术凭借其独特的优势,逐渐在各个领域展现出强大的生命力。而IoT网关,作为连接物理世界与数字世界的桥梁,其在物联网体系中的作用愈发凸显。 一、数据聚合与预处理…...

继承实现单例模式的探索(一)
前言 之前看到朋友采用继承的方式来实现单例模式,觉得很厉害,随后自己去探索了一番,以前实现单例模式都是把代码内联到具体的类中,这使得工程中每次需要使用单例模式时,都采用拷贝的方式,增加了很多冗余代码…...

【代码实现】opencv 高斯模糊和pytorch 高斯模糊
wiki百科 Gaussian Blur,也叫高斯平滑,是在Adobe Photoshop、GIMP以及Paint.NET等图像处理软件中广泛使用的处理效果,通常用它来减少图像噪声以及降低细节层次。 opencv实现 opencv实现高斯滤波有两种方式, 1、是使用自带的cv2…...

python基础语法2
文章目录 1.顺序语句2.条件语句2.1 语法格式 3.缩进与代码块4.空语句 pass5.循环语句5.1 while循环5.2 for循环 5.3 continue与break 1.顺序语句 默认情况下,python的代码都是按照从上到下的顺序依次执行的。 print(hello ) print(world)结果一定是hello world。写…...