Perl: Get new packages, send emails, and call other programs

Source: Internet
Author: User

According to Xiao Peng, first change the detection script of yesterday to the one with the reset function, and then send the alarm prompt to the specified mailbox by email.

Certificate ---------------------------------------------------------------------------------------------------------------------------------------

Http://lvdbing.blog.163.com/blog/static/55801529200832111630600/ (here also explains how to use Perl to send mail, refer to the web page)

 

UseNet: smtp_authFirst installNet: smtp_authModule.

1. Windows Operating System: If ActivePerl is used in windows, the installation directory of ActivePerl is executable.ProgramDirectory, that is, the bin directory. (For example: C: \ Perl \ bin) execute the command ppm-shell, (ppm:Perl Package Manager

Perl Package Manager), and then execute the command:

C: \ Perl \ bin>PPM-shell
PPM 4.01
Copyright (c) 2007 ActiveState Software Inc. All rights reserved.
Ppm>Install net: smtp_auth

2. Linux operating system:If Perl is used in the Linux operating system, you can use the command CPAN followed by the module to be installed. (If CPAN is used for the first time, you need to configure some information about CPAN and keep following the default settings ).

Root@lvdbing.net ~ # CPAN net: smtp_auth


PS:The emails mentioned on the webpage can indeed be sent, but garbled characters may occur during Chinese sending. So I found a solution on the Internet. The following is a feasible solution.

We often send Chinese emails, but the email code is not the same as that written on the web. We generally use base64 encoding to process non-ASCII characters in the mail header. Now UTF-8 is the most common coding on the web.
 Code 
   $ SMTP  ->  Datasend (  "  Content-Type: text/plain; charset = UTF-8 \ n  "  );  #  Set the email Content Encoding here. 
$ SMTP -> Datasend ( " Subject: =? UTF-8? B? " . Encode_base64 ( $ Title , '' ) . " ? = \ N " ); # Encode_base64 is MIME: a function in the base64 module, $ title is encoded by the UTF-8
$ SMTP -> Datasend ( $ Mail_body . " \ N " ); # $ Mail_body is UTF-8 encoded

 

 
Where =? UTF-8? B? Is prefix ,? = Is a suffix. B Indicates base64 encoding. In the title of the mail header, you must first use UTF-8 encoding, and then use base64 encoding, and the mail body can directly use the UTF-8 encoding.
Such emails do not contain Chinese garbled characters.

Http://www.belltoy.net/chinese-in-email.html

 

Certificate ---------------------------------------------------------------------------------------------------------------------------------------

 

Perl calls other Program Methods

1. System ("command ");

Use this command to enable a sub-process to execute the command in quotation marks. The parent process will wait until the sub-process ends and continue to execute the followingCode.

2. Exec ("Command ");
The effect is similar to that of the system command. The difference is that the sub-process is not enabled, but the parent process is replaced. Therefore, after the command in quotation marks is executed, the process ends. Generally used in combination with fork.

3. 'command ';
An external command can be called with backquotes to capture its standard output, return by line, and a carriage return is attached at the end of each line. Variables in the back quotes are interpolated as their values during compilation.

4. Open list "LS-L | ";
Open more "| more ";
@ List =;
Print more @ list;
Close (list );
Close (more );
Use a file handle with an MPS queue to execute External commands, which is similar to reading and writing files. Data can be read from the output of External commands, or output to external commands as input.

5. defined (my $ pid = fork) or die "can not fork: $! \ N ";
Unless ($ PID ){
Exec ("date ");
}
Waitpid ($ PID, 0 );
If fork is used, the code after both the sub-process and the parent process are enabled. Fork in the parent process returns a non-zero number, and the sub-process returns zero.
The code above completes the same functions as system ("date. Fork can perform more complex process operations than simply calling external commands by system.

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.