From 8905b97ae2b4cf71adb211d1eb14c35bedefc11c Mon Sep 17 00:00:00 2001 From: lsy Date: Fri, 26 Jul 2024 18:45:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=98=E5=86=99=E6=97=B6=E9=97=B4=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Config/Automation/backup.sh | 28 +--------------------------- Config/Automation/update.sh | 1 + Menus/Automation.sh | 30 +++++++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/Config/Automation/backup.sh b/Config/Automation/backup.sh index df5c06c..1371150 100644 --- a/Config/Automation/backup.sh +++ b/Config/Automation/backup.sh @@ -1,11 +1,11 @@ #!/bin/bash declare path=$1 +declare cron=$2 declare web_path declare local_pick declare baidu_pick declare aliyun_pick -declare -a cron_array=("分钟" "小时" "天数" "月份" "星期" ) declare cron if [[ -f "${path}/update.sh" ]];then @@ -63,32 +63,6 @@ if [[ ! $aliyun_pick =~ [Nn] ]];then ./aliyunpan login fi -echo -echo "执行日期" -echo "星号(*):表示匹配任意值" -echo "逗号(,):用于分隔多个值" -echo "斜线(/):用于指定间隔值" -echo "连字符(-):用于指定范围" - -declare tmp_time -for i in "${cron_array[@]}";do - read -p "${i},默认为 * :" tmp_time - if [[ $tmp_time =~ ^[0-9]+$ || $tmp_time == '*' ]];then - cron+="${tmp_time} " - elif [[ -z ${tmp_time} ]];then - cron+='* ' - else - echo "输入错误" - exit - fi -done -if [[ "$cron" == '* * * * * ' ]];then - read "该脚本会无时无刻执行,请重新输入" - exit -fi - - - cat > "${path}/backup.sh" << EOF #!/bin/bash declare date_time=$(date +"%Y_%m_%d") # 日期格式 diff --git a/Config/Automation/update.sh b/Config/Automation/update.sh index 1bc9ab8..2e14086 100644 --- a/Config/Automation/update.sh +++ b/Config/Automation/update.sh @@ -1,5 +1,6 @@ declare version=$(cat /etc/os-release | grep '^ID' | awk -F '=' '{print $2}') declare path=$1 +declare cron=$2 if [[ -f "${path}/update.sh" ]];then echo "该路径文件已经存在" diff --git a/Menus/Automation.sh b/Menus/Automation.sh index 1d1ff84..5eff1d3 100644 --- a/Menus/Automation.sh +++ b/Menus/Automation.sh @@ -21,13 +21,37 @@ if [[ -z $path ]];then fi mkdir -p "$path" +echo "执行日期" +echo "星号(*):表示匹配任意值" +echo "逗号(,):用于分隔多个值" +echo "斜线(/):用于指定间隔值" +echo "连字符(-):用于指定范围" + +declare tmp_time +declare -a cron_array=("分钟" "小时" "天数" "月份" "星期" ) +for i in "${cron_array[@]}";do + read -p "${i},默认为 * :" tmp_time + if [[ $tmp_time =~ ^[0-9]+$ || $tmp_time == '*' ]];then + cron+="${tmp_time} " + elif [[ -z ${tmp_time} ]];then + cron+='* ' + else + echo "输入错误" + exit + fi +done +if [[ "$cron" == '* * * * * ' ]];then + read "该脚本会无时无刻执行,请重新输入" + exit +fi + case $pick in '1') - bash Config/Automation/backup.sh "$path" + bash Config/Automation/backup.sh "$path" "$cron" ;; '2') - bash Config/Automation/update.sh "$path" + bash Config/Automation/update.sh "$path" "$cron" ;; '3') if ! command -v docker &> /dev/null; then @@ -61,6 +85,6 @@ EOF sudo systemctl restart cron 2>> /dev/null || echo "自动任务重启失败" ;; '4') - echo "国内忘写了" + echo "糟糕忘写了" esac echo "配置完成" \ No newline at end of file