使用 curl 检查 bash 中是否存在 url 列表 [英] Check if a list of urls exist or not in bash with curl

查看:55
本文介绍了使用 curl 检查 bash 中是否存在 url 列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检查网址列表是否有效.我正在尝试这个 Bash,但我没有得到正确的语法.

 用于 $(cat domain.txt) 中的 url做 curl --output/dev/null --silent --head --fail "$url";然后echo "URL 存在:$url"别的echo "URL 不存在:$url"完毕

谁能帮我一把?

解决方案

您缺少一个 if(以及相应的 fi)来使您的代码正常工作.

>

#!/bin/bash对于 $(cat domain.txt) 中的 url做if curl --output/dev/null --silent --head --fail "$url";然后echo "URL 存在:$url"别的echo "URL 不存在:$url"菲完毕

I'm trying to check if a list of urls are valid or not. I'm trying this Bash but I'm no getting the correct syntax.

for url in $(cat domains.txt) 
do curl --output /dev/null --silent --head --fail "$url"; then
  echo "URL exists: $url"
else
  echo "URL does not exist: $url"
done

Can anyone give me a hand?

解决方案

you're missing an if (and corresponding fi) to make your code work.

#!/bin/bash
for url in $(cat domains.txt) 
do 
  if curl --output /dev/null --silent --head --fail "$url"; then
    echo "URL exists: $url"
  else
    echo "URL does not exist: $url"
  fi 
done

这篇关于使用 curl 检查 bash 中是否存在 url 列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆