linux 脚本二次验证

RED='\e[31m'
GREEN='\e[32m'
NC='\e[0m'

echo -e "你将执行以下操作:***${RED}${task_script}${NC}***"
if [[ -z ${only_ip} ]];then
  echo -e "即将操作IP文件为:${host_file}"
  echo "IP文件内容:"
  head -n 5 ${host_file}
  ip_num=`cat ${host_file} |wc -l`
  echo -e "IP文件中IP数目:${RED}${ip_num}${NC}"
fi
# 二次确认
read -p "您确定要继续吗?(y/n): " confirm

# 检查用户输入
case $confirm in
[yY][eE][sS]|[yY])
echo -e "${GREEN}操作已确认,正在执行...${NC}"
if [[ -z ${only_ip} ]];then
T_log_success "run file ${host_file} begin ${task_script}" | tee ${LOG_DEBUG}
v_host_list=($(cat ${host_file}))
f_batch_run ${#v_host_list[@]} ${task_script}
T_log_success "run file ${host_file} finish ${task_script}" | tee -a ${LOG_DEBUG}
else
f_test ${only_ip} ${task_script}
fi
;;
[nN][oO]|[nN])
echo -e "${RED}操作已取消。${NC}"
exit 1
;;
*)
echo -e "${RED}无效输入,请输入 y 或 n。${NC}"
exit 1
  ;;
esac

posted @ 2025-05-23 14:04  杰尔克  阅读(12)  评论(0)    收藏  举报