Linux常用脚本

关闭jar包

#!/bin/bash

PID=$(ps -ef | grep xxx.jar | grep -v grep | awk '{print $2}')

if [ ! $PID ]; then
    echo "process ${jar_name} not exit"
    exit
else
    echo "process id: $PID"
fi

kill -9 ${PID}

if [ $? -eq 0 ]; then
    echo "kill ${jar_name} success"
else
    echo "kill ${jar_name} fail"
fi

创建备份文件夹


# 获取当前日期
current_date=$(date +%Y%m%d)

# 定义固定字符串
fixed_string="bak"

# 定义文件夹名称
folder_name="${current_date}${fixed_string}"

# 检查文件夹是否存在
if [ -d "$folder_name" ]; then
  # 如果存在,则添加后缀
  suffix=2
  while [ -d "${folder_name}-${suffix}" ]; do
    ((suffix++))
  done
  folder_name="${folder_name}-${suffix}"
fi

# 创建文件夹
mkdir "$folder_name"

echo "已创建文件夹:$folder_name"

启动jar

nohup java -DproxyHost=xx.xxx.x.xxx -DproxyPort=80 -Dhttp.nonProxyHosts="_.xxx.net|_.xxx.com|localhost|10.xxx.*" -Dspring.profiles.active=sit -jar volkRed-0.0.1.jar --server.port=8032 >nohup-image.out &
nohup java -Xms512m -Xmx512m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -Dspring.profiles.active=prod  -jar xxx.jar --server.port=8020 >nohup-customization.out &