增加了脚本删除

This commit is contained in:
lsy 2024-09-27 13:11:37 +08:00
parent 2648050922
commit d116655891
3 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,52 @@
#!/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')
for i in "$path"/* ; do
if [[ $i == "${path}/*" ]];then
echo "该地址不存在脚本"
fi
echo $i
done
;;
'2')
declare -a script_arr
declare script_name
declare script_number=0
for i in "$path"/* ; do
if [[ $i == "${path}/*" ]];then
echo "该地址不存在脚本"
exit
fi
script_number=$(( script_number+1 ))
script_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
echo "${script_number}.${script_name}"
script_arr[$script_number]=$script_name
done
read -p "请输入要删除的序号,多个用 空格 隔开:" script_name
for i in $script_name ; do
if [[ $i =~ [1-${#script_arr[*]}] ]]; then
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
echo "删除完成"
;;
esac

View File

@ -30,6 +30,10 @@ case $pick in
declare site_name declare site_name
declare site_number=0 declare site_number=0
for i in "$path"/* ; do for i in "$path"/* ; do
if [[ $i == "${path}/*" ]];then
echo "该地址不存在站点"
exit
fi
site_number=$(( site_number+1 )) site_number=$(( site_number+1 ))
site_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)") site_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
echo "${site_number}.${site_name}" echo "${site_number}.${site_name}"