centos下簡單實現日誌切割,並上傳至Log Service器。

來源:互聯網
上載者:User

標籤:伺服器   expect   count   日誌切割   

#!/bin/bash

#大於500M的日誌上傳至Log Service器並清除

count=$[1024*1024*500]#500M

file_size=`ll /var/log/httpd/access_log| awk ‘{print $5}‘` 

passwd="magedu.com"#注意變數最好在expect外定義,不知道什麼原因我在expect裡面定義不成功

if [ $file_size -gt $count ]

then 

   /usr/bin/expect << EOF

     spawn scp /var/log/httpd/access_log 192.168.25.129:/root/logdata/ #spawn用來執行shell命令

    expect "password" #命令執行後,如果檢測到“password”提示資訊就執行下面的命令

    send "$passwd\n" #向終端傳送密碼

    expect eof #expect結束標誌,必須有,沒有報錯

EOF

    echo " " > /var/log/httpd/access_log #將日誌清空

fi

    

     

    


centos下簡單實現日誌切割,並上傳至Log Service器。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.