linuxtool/Config/Automation/manage.sh

72 lines
1.9 KiB
Bash
Raw Normal View History

2024-09-27 13:11:37 +08:00
#!/bin/bash
echo "1.查看已经安装的脚本"
echo "2.删除脚本"
declare pick
read -p "请输入:" pick
declare path="/var/script"
echo "请输入脚本安装地址,默认${path}"
read -p "请输入:" path
if [[ -z $path ]]; then
path="/var/script"
elif ! [[ -d $path ]]; then
echo "该地址不存在目录"
fi
case $pick in
'1')
2024-09-27 14:45:16 +08:00
declare -a script_arr
declare script_name
declare script_number=0
2024-09-27 13:11:37 +08:00
for i in "$path"/* ; do
if [[ $i == "${path}/*" ]];then
echo "该地址不存在脚本"
2024-09-27 14:45:16 +08:00
exit
fi
script_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
if [[ $script_name == "linuxtool" ]]; then
continue
2024-09-27 13:11:37 +08:00
fi
2024-09-27 14:45:16 +08:00
script_number=$(( script_number+1 ))
echo "${script_number}.${script_name}"
script_arr[$script_number]=$script_name
2024-09-27 13:11:37 +08:00
done
2024-09-27 14:45:16 +08:00
if [ ${#script_arr[@]} == 0 ]; then
echo "该地址不存在脚本"
exit
fi
2024-09-27 13:11:37 +08:00
;;
'2')
declare -a script_arr
declare script_name
declare script_number=0
for i in "$path"/* ; do
if [[ $i == "${path}/*" ]];then
echo "该地址不存在脚本"
2024-09-27 14:45:16 +08:00
exit
2024-09-27 13:11:37 +08:00
fi
script_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
2024-09-27 13:20:43 +08:00
if [[ $script_name == "linuxtool" ]]; then
continue
fi
script_number=$(( script_number+1 ))
2024-09-27 13:11:37 +08:00
echo "${script_number}.${script_name}"
script_arr[$script_number]=$script_name
done
2024-09-27 14:45:16 +08:00
if [ ${#script_arr[@]} == 0 ]; then
echo "该地址不存在脚本"
exit
fi
2024-09-27 13:11:37 +08:00
read -p "请输入要删除的序号,多个用 空格 隔开:" script_name
for i in $script_name ; do
2024-09-27 14:45:16 +08:00
if [[ $i =~ [1-${#script_arr[@]}] ]]; then
2024-09-27 13:11:37 +08:00
echo "开始删除 ${script_arr[$i]}"
(crontab -l 2>/dev/null | grep -v "${script_arr[$i]}") | crontab - && echo "已经删除脚本的自动任务"
rm -rf "$path/${script_arr[$i]}" &> /dev/null
echo "删除完成"
fi
done
;;
esac