shell並發上傳ftp

來源:互聯網
上載者:User

標籤:shell

2年前在藍汛的時候管理的一個CDN節點, 因某些特殊原因, 沒有採用藍汛標準的系統管理方法...

為瞭解決日誌收集的問題, 自己寫了一個shell並發的小指令碼....

有時日誌傳輸會出現一些問題, 會產生一些日誌堆積,  有時上千個~...單進程傳輸效率實在太底下了..就寫了這麼一個指令碼...

主要並發是, 通過判斷要傳的目錄下有多少個檔案, 當前啟動並執行進程是多少個, 達到上限就等待...不足上限就繼續傳...

#!/bin/bash# Chinacache CPIS-OPT# $Id: upload_log.sh 2012-9-18 19:10 HGL#---------------------------------------------------------------------------|#  @Program   : upload_log.sh                                               |  #  @Version   : 1.0.1                                                       |#  @Company   : china cache                                                 |#  @Dep.      : CPIS-OPT                                                    |#  @Writer    : Kevin.han                                                   |#  @Date      : 2012-9-18                                                   |#---------------------------------------------------------------------------|log_dir=/data/proclog/log/squid/access/.upload/.CPISNLAuser=123pass=123ftpip="1.1.1.1:21"init=1max=5logdir=( `ls $log_dir` )for (( i=0;i<=$init;i++ ));doif [ $i -ge ${#logdir[@]} ];thenexit 0filftp ftp://${user}:${pass}@${ftpip} -e "cd 2nd_edition/temp;put -c -E ${log_dir}/${logdir[$i]} -o ${logdir[$i]}.tmp;mv ${logdir[$i]}.tmp ${logdir[$i]};exit"  &if [ $i -eq $init ];then                        a=`ps -eo command|grep lftp|grep -v grep|wc -l`                while (( $a > 10 ));do                        sleep 5                        a=`ps -eo command|grep lftp|grep -v grep|wc -l`                donelet b=${#logdir[@]}-$iif [ $max -ge $b ];then                let init=$init+$belselet init=$init+$maxfifidone

 


本文出自 “曉風殘月” 部落格,請務必保留此出處http://kinda22.blog.51cto.com/2969503/1582561

shell並發上傳ftp

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.