- 论坛徽章:
- 1
|
發信用的Email..會將純文字的文件寄送出去...
- #!/usr/bin/perl
- #---------------------------------------------------------------
- #fileName: mail_perl:發送測試用的Email
- #---------------------------------------------------------------
- use Mail::Sender;
- ## 幫助Debug使用
- use Carp();
- local $SIG{__WARN__} = \&Carp::cluck;
- ## 將Standard Error儲存至檔案
- open(STDERR,">;>;/tmp/mail_err.log");
- #local($to,$subject,$filename,$from,$server_ip,$replyto) =@_;
- ## 取得輸入參數
- $to=shift;
- $subject = shift;
- $filename=shift;
- $filename=~/(\/.*\/)(.*)/;
- ## 取得附加檔名
- $file= $2;
- $from=shift;
- $server_ip=shift;
- $replyto= shift;
- $fake_from =shift;
- #print "$to,$subject,$filename,$from,$server_ip,$replyto\n";
- # 定義smtp server,client是從哪來的
- ref($sender = new Mail::Sender {
- smtp =>; "$server_ip",
- client =>; '10.1.1.1',
- boundary=>; 'this-is-a-mail-boundary-435427' })
- or die "Error in mailing: $Mail::Sender::Error\n";
- # 開啟multi part的object,定義to,from,fake_from,charset,replyto,subject等變數
- $sender->;OpenMultipart({to=>;"$to",
- from =>;"$from",
- fake_from =>; "$fake_from",
- charset=>;'Big5',
- replyto =>;"$replyto",
- subject =>; "$subject"});
- # 寫內文
- $sender->;Body({charset=>;'big5',ctype=>;'text/plain'});
- $sender->;Send(<<"*END*");
- 這是一封由系統自動告知信件,請查收..謝謝您!!!
- --------------------
- *END*
- # 開始附加檔案部分,先要瞭解附加檔案是什麼型態,
- # 本範例是純文字檔,所以ctype使用的是text/plain,如果是gif要使用image/gif
- # ,dispositiion會影響user看到的檔案名稱,如果有/xx/xx/ttt.txt會顯示成
- # _xx_xx_ttt.txt ,"_"會被替代成"/"
- $sender->;Attach({ description=>;"$file",
- ctype=>;'text/plain',
- disposition=>;"attachment;filename=$file",
- file=>;"$filename"
- })
- || die "Error in attachment: $Mail::Sender::Error\n";
- $sender->;Close;
复制代码
產生前一天日期的代碼
- #!/usr/bin/perl
- # fileName: predate
- my %mon=(
- 1 =>; "Jan", 2 =>; "Feb", 3 =>; "Mar", 4 =>; "Apr",
- 5 =>; "May", 6 =>; "Jun", 7 =>; "Jul", 8 =>; "Aug",
- 9 =>; "Sep", 10 =>; "Oct", 11 =>; "Nov", 12 =>; "Dec"
- );
- my ($sec1,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time-86400);
- $mon++;
- $mon=$mon{$mon};
- $mday = sprintf("%02s",$mday);
- $hour = sprintf("%02s",$hour);
- $min = sprintf("%02s",$min);
- $sec = sprintf("%02s",$sec);
- $year+=1900;
- print "$mday/$mon/$year\n";
复制代码
前一天登錄超過五百次者,將他的IP Address記錄下來...
由大到小排序
- #!/usr/bin/perl
- # check_apache.pl
- while(<>;){
- chomp;
- $aa{$_}++;
- }
- open (FF,">;/apile/record.txt");
- my($predate)=`/apile/predate`;
- chomp($predate);
- print FF "------- APACHE 登錄檔記錄------------\r\n";
- print FF "--紀錄日期:$predate 登錄筆數大於500筆者\r\n";
- print FF "---------------------------------------------\r\n";
- for (reverse sort { $aa{$a}<=>;$aa{$b}} keys %aa){
- if( $aa{$_} >; 500){
- print FF "$_ =>; $aa{$_} \r\n";
- }
- }
- print FF "---------------------------------------------\r\n";
- close(FF);
复制代码
- #!/usr/bin/ksh
- # check_apache.sh
- PATH=/usr/bin:/sbin:/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
- export PATH
- Date=`/apile/predate`
- echo "cat /usr/local/apache/logs/access_log|grep $Date | awk '{printf("%s\n",$1)}'|
- /apile/check_apache.pl"
- cat /usr/local/apache/log/access_log|grep "$Date" | awk '{printf("%s\n",$1)}'|/apile/check_apache.pl
- /apile/mail_perl "apile@abc.cde" " APACHE登錄檔檢查每日定時回報" "/apile/record.txt" "apile@abc.cde" "10.2.2.2" "apile@abc.cde" "FAKEMAIL@fake.fake"
复制代码
使用方式:crontab -e
00 17 * * 0-5 /apile/check_apache.sh 1>;/tmp/apache.log 2>;/tmp/apache.err
Email附件如下:(record.txt)
-------APACHE 登錄檔記錄------------
--紀錄日期:17/Aug/2003 登錄筆數大於500筆者
---------------------------------------------
10.1.17.80 =>; 1848
10.1.17.65 =>; 1834
10.1.17.66 =>; 1607
10.1.17.85 =>; 1403
10.1.17.51 =>; 1345
10.1.17.52 =>; 1027
10.1.17.84 =>; 860
10.1.17.54 =>; 849
10.1.17.86 =>; 690
10.1.17.81 =>; 674
10.1.17.50 =>; 655
10.1.17.64 =>; 619
10.1.17.69 =>; 619
10.1.17.67 =>; 593
10.1.17.83 =>; 575
10.1.17.57 =>; 512
10.1.17.55 =>; 505
-------------------------------------------
這只是簡單的記錄那個IP Address登錄了幾次...
功能不完整,但還可以用,因為最近我維護的系統
不穩定,就讓我用這個程序抓到有人在三天內連接
了超過5萬次..讓我的系統非常不穩定.. |
|