shell 可控并发实现

1、实现分析日志 并发查询ip 归属

#!/bin/bash
# access single 2 (ctrl+c)
  trap "exec 99>&-;exec 99<&-;exit 0" 2
# create fifo
  mkfifo tmpfifo
# bond fd to fifo
  exec 99<>tmpfifo
#setup THREAD_NUM 
  THREAD_NUM=100
  for ((n=1;n<=$THREAD_NUM;n++))
    do 
       echo "\n" >&99
    done
#main 
  while read access_num ip
    do
    {
      read -u 99 
       { address=curl --connect-timeout 5 http://ip.taobao.com/service/getIpInfo.php?ip=$ip 2&gt;/dev/null
         ip_address=echo -e "$address"|tr -s ',' '\n'|grep -E '("area"|"city"|"ip")'|tr -d } |tr -s '\n' ' '
         echo "$ip_address \"access_num\": \"$access_num\"" >> ip_address.txt
     #keep THREAD_NUM 
       echo "\n" >&99  
      }&
 }
    done <$1
    wait 
echo "run over "
# unbond fd to fifo
exec 99>&-
exec 99<&-
rm tmpfifo

2、淘宝查询ip归属 API
curl --connect-timeout 5 http://ip.taobao.com/service/getIpInfo.php?ip=$ip

Pingbacks已打开。

引用地址

评论
  1. Strandfeest Hoek van Holland Strandfeest Hoek van Holland 发布于 2021年4月18日 01:57 #

    Heya terrific blog! Does running a blog similar to this require a lot of work?
    I have virtually no knowledge of coding but I was hoping to start my own blog in the
    near future. Anyhow, should you have any ideas or techniques for new blog owners
    please share. I understand this is off subject nevertheless I just had to ask.
    Thanks!

  2. Strandfeest Hoek van Holland Strandfeest Hoek van Holland 发布于 2021年4月18日 01:57 #

    Heya terrific blog! Does running a blog similar to this require a lot of work?

    I have virtually no knowledge of coding but I was hoping to
    start my own blog in the near future. Anyhow, should you have
    any ideas or techniques for new blog owners please share.
    I understand this is off subject nevertheless I just had to ask.
    Thanks!

  3. Manueel praktijk 't Gooi Manueel praktijk 't Gooi 发布于 2021年4月18日 02:12 #

    Hi there just wanted to give you a quick heads up and let you know a few
    of the pictures aren't loading correctly. I'm not sure why but I think its a linking issue.
    I've tried it in two different web browsers and both show the same
    results.

  4. Manueel praktijk 't Gooi Manueel praktijk 't Gooi 发布于 2021年4月18日 02:12 #

    Hi there just wanted to give you a quick heads up and let you know
    a few of the pictures aren't loading correctly. I'm not sure why but I think its a
    linking issue. I've tried it in two different web browsers and both show the same results.

  5. All Google search options All Google search options 发布于 2021年4月18日 03:11 #

    I am regular reader, how are you everybody? This article posted at this website is really nice.

  6. All Google search options All Google search options 发布于 2021年4月18日 03:11 #

    I am regular reader, how are you everybody? This article posted at this
    website is really nice.

发表评论