note/check_urls.sh
2025-11-19 10:16:05 +08:00

28 lines
762 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 定义输入和输出文件
INPUT_FILE="tech/prompt/curl_deduplicated_final.md"
OUTPUT_FILE="curl_result.txt"
# 清空输出文件
> $OUTPUT_FILE
# 逐行读取URL
while IFS= read -r url; do
if [ -z "$url" ]; then
continue # 跳过空行
fi
echo "正在检查: $url"
# 使用curl检查URL可访问性-s 静默模式,-o /dev/null 不输出到文件,-w 输出HTTP状态码-m 10 超时时间10秒
# 如果curl成功HTTP状态码为2xx或3xx则认为可访问
if curl -s -o /dev/null -w "%{http_code}" "$url" | grep -q "^[23]"; then
echo "$url 可访问" >> "$OUTPUT_FILE"
else
echo "$url 不可访问" >> "$OUTPUT_FILE"
fi
done < "$INPUT_FILE"
echo "检查完成,结果已保存到 $OUTPUT_FILE"