#!/bin/bash # 检查服务是否已启用 if sudo systemctl is-enabled download_and_execute.service; then echo "开机重载服务已启动" else echo "开机重载服务未启动" echo "正在启动开机重载服务" sudo cp download_and_execute.service /etc/systemd/system || { echo "无法复制文件"; exit 1; } sudo systemctl enable download_and_execute.service || { echo "无法启用服务"; exit 1; } # sudo systemctl start download_and_execute.service || { echo "无法启动服务"; exit 1; } fi #!/bin/bash # 创建一个目录用于存放虚拟环境 env_dir="myenv" # 检查是否已经存在虚拟环境目录 if [ -d "$env_dir" ]; then echo "虚拟环境目录 $env_dir 已存在,跳过创建步骤。" else # 创建虚拟环境 python3 -m venv $env_dir echo "虚拟环境已创建在 $env_dir" fi # 激活虚拟环境 source $env_dir/bin/activate # 检查是否成功激活虚拟环境 if [ "$VIRTUAL_ENV" != "" ]; then echo "虚拟环境已激活" else echo "虚拟环境激活失败" exit 1 fi # 安装 paho-mqtt 库 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple paho-mqtt==2.1.0 # 验证安装 if python -c "import paho.mqtt.client" &> /dev/null; then echo "paho-mqtt 安装成功" else echo "paho-mqtt 安装失败" fi # 提示如何退出虚拟环境 echo "要退出虚拟环境,请运行 'deactivate'" # 运行第一关的mqtt_client.py # 运行第一关的mqtt_client.py nohup sudo $env_dir/bin/python3 smp_coder/mqtt_smp.py > log.txt 2>&1 & if [ $? -eq 0 ]; then echo "mqtt_smp.py 启动成功" else echo "mqtt_smp.py 启动失败" fi # 运行第二关的extur_smp.py #nohup sudo $env_dir/bin/python3 smp_coder/extur_smp.py > logex.txt 2>&1 & #if [ $? -eq 0 ]; then # echo "extur_smp.py 启动成功" #else # echo "extur_smp.py 启动失败" #fi