帮我写一个jar服务替换更新运行的脚本。在opt下有 api-activiti api-scm api-web service-gateway service-oauth 5个目录。并且每个目录下的jar名称都是目录名加上-100jar例如api-external目录下的jar名称是api-external-100jar其他4个格式一样。首先需要判断rootjarfile 下有那些jar
#!/bin/bash
Define the directories and jar filenames
directories=(api-activiti api-scm api-web service-gateway service-oauth) jar_suffix="-1.0.0.jar"
Check if /root/jarfile directory exists
if [ ! -d "/root/jarfile" ]; then echo "/root/jarfile directory doesn't exist." exit 1 fi
Move jar files to corresponding directories
for jar_file in /root/jarfile/*; do if [ -f "$jar_file" ]; then jar_name=$(basename "$jar_file") for directory in "${directories[@]}"; do if [[ "$jar_name" == "$directory$jar_suffix" ]]; then mv "$jar_file" "/opt/$directory/" echo "Moved $jar_name to /opt/$directory/" break fi done fi done
Restart jar services with 10 seconds buffer
for directory in "${directories[@]}"; do sh "/opt/$directory/operate.sh" restart echo "Restarted $directory with 10 seconds buffer." sleep 10 done
echo "All jar services have been restarted."
原文地址: https://www.cveoy.top/t/topic/bhIM 著作权归作者所有。请勿转载和采集!