Chinaunix首页 | 论坛 | 博客
  • 博客访问: 478755
  • 博文数量: 279
  • 博客积分: 4467
  • 博客等级: 上校
  • 技术积分: 2830
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-03 14:43
文章分类

全部博文(279)

文章存档

2013年(1)

2012年(39)

2011年(35)

2009年(29)

2008年(131)

2007年(44)

分类:

2007-11-27 16:35:27

Emailautoreply: shell



perl1:





#!/bin/sh
#get current time
date>ping.txt
#ping cmd test
ping -c 5 portal.uniforce.net>>ping.txt
#get HTML code
wget -l 2 http://portal.uniforce.net
#compare
diff index.html index.html.1>different
cat different>>ping.txt
if test -s different;
then
#HTML wrong
perl perl2
else
#HTML right
perl perl1
fi
#refresh
rm -f index.html

#!/usr/bin/perl

open (PING,"ping.txt")or die "cannot open ping.txt$!\n";
$ping=<PING>."\n";

use MIME::Lite;
use Net::SMTP;

### Adjust sender, recipient and SMTP mailhost

my $from_address = 'seven.zhang@uniforce.net';
my $to_address = 'leif.liang@uniforce.net,op@uniforce.net,seven.zhang@uniforce.net';
my $mail_host = 'nxserver.sh.uniforce.net';
my $result='portal.uniforce.net can be access';
### Adjust subject and body message

my $subject = 'uniforce portal check';

### Adjust the filenames

my $my_file_html = 'index.html';
my $your_file_html = 'index.html';

### Create the multipart container


$msg = MIME::Lite->new (
  From => $from_address,
  To => $to_address,
  Subject => $subject,
  Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";

### Add the text message part

$msg->attach (
  Type => 'TEXT',
  Data => $ping.$result,
) or die "Error adding the text message part: $!\n";

### Add the html file

$msg->attach (
   Type => 'HTML',
   Path => $my_file_html,
   Filename => $your_file_html,
   Disposition => 'html'
) or die "Error adding $file_html: $!\n";


### Send the Message

MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;

perl2:

#!/usr/bin/perl

open (PING,"ping.txt")or die "cannot open ping.txt ";
$ping=<PING>."\n";

use MIME::Lite;
use Net::SMTP;

### Adjust sender, recipient and SMTP mailhost

my $from_address = 'seven.zhang@uniforce.net';
my $to_address = 'leif.liang@uniforce.net,op@uniforce.net,seven.zhang@uniforce.net';
my $mail_host = 'nxserver.sh.uniforce.net';
my $result1='portal.uniforce.net cannot be access';

### Adjust subject and body message

my $subject = 'uniforce portal check';


### Adjust the filenames

my $my_file_html = 'index.html';
my $your_file_html = 'index.html';

### Create the multipart container


$msg = MIME::Lite->new (
  From => $from_address,
  To => $to_address,
  Subject => $subject,
  Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";

### Add the text message part

$msg->attach (
  Type => 'TEXT',
  Data => $ping.$result1,
) or die "Error adding the text message part: $!\n";

### Add the html file

$msg->attach (
   Type => 'HTML',
   Path => $my_file_html,
   Filename => $your_file_html,
   Disposition => 'html'
) or die "Error adding $file_html: $!\n";


### Send the Message

MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;

阅读(215) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~