LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2075|回复: 5

这个perl脚本应该怎么改?

[复制链接]
发表于 2006-9-20 12:52:10 | 显示全部楼层 |阅读模式
  1. #!/usr/bin/perl
  2. # Put this in ~/.gmail/ and use "crontab -e" to add something like
  3. # "* * * * * ~/.gmail/gmail.pl > /dev/null" to run it every minute.
  4. # ${exec cat ~/.gmail/.gmail_top} shows your inbox in Conky.
  5. # Note that this was intended to be used with Gmail or any other
  6. # ssl-enabled pop3 server.
  7. # beginning of configuration
  8. # pop3 host
  9. $pop_host = "pop.gmail.com";
  10. # pop3 username (for Gmail, I didn't have to put @gmail.com at the end)
  11. $pop_user = "xxxxxx";
  12. # pop3 password
  13. $pop_pass = "xxxxx";
  14. # ssl port number (995 is what Gmail uses)
  15. $ssl_port = "995";
  16. # ssl protocol
  17. $ssl_prot = "tcp";
  18. # number of emails to show
  19. $dis_numb = "3";
  20. # end of configuration
  21. use Mail::POP3Client;
  22. use IO::Socket::SSL;
  23.   my $socket = IO::Socket::SSL->new( PeerAddr => $pop_host,
  24.                                      PeerPort => $ssl_port,
  25.                                      Proto    => $ssl_prot);
  26.   my $pop = Mail::POP3Client->new();
  27.   $pop->User($pop_user);
  28.   $pop->Pass($pop_pass);
  29.   $pop->Socket($socket);
  30.   $pop->Connect();
  31. $msg_count = $pop->Count();
  32. for ($i = $msg_count, $j = 0; $i >= $msg_count-($dis_numb-1); $i--, $j++) {
  33.   foreach ( $pop->Head( $i ) ) {
  34.     #/^(From|Subject):\s+/i and print $_, "\n";
  35.     if ($_ =~ m/^From:/) {
  36.       ($from) = ($_ =~ m#^From: .*<(.*)>#);
  37.       $from = substr($from, 0, 30);
  38.       $out .= "$j = $from\n";
  39.     }
  40.   }
  41.   #chop $out;
  42.   `echo -e "$out"> ~/.gmail/.gmail_top`;
  43. }
  44. $pop->Close();
复制代码

本来是想放在conky里来自动监测邮件的,但是这个脚本好像有问题,我直接运行的结果:
  1. ./gmail.pl
  2. Can't locate Mail/POP3Client.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at ./gmail.pl line 31.BEGIN failed--compilation aborted at ./gmail.pl line 31.
复制代码
发表于 2006-9-20 17:52:05 | 显示全部楼层
注意看出错信息
上CPAN搜 Mail:OP3Client 然后装之
回复 支持 反对

使用道具 举报

发表于 2006-9-20 17:53:44 | 显示全部楼层
cpan -i Mail:OP3Client
搞定。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-20 23:12:23 | 显示全部楼层
Post by 终极幻想
cpan -i Mail:OP3Client
搞定。
cpan -i Mail:OP3Client能成功装
但cpan -i IO::Socket::SSL却不行,我已经装了openssl(0.9.8b-3)
  1. sudo cpan -i IO::Socket::SSL
  2. CPAN: Storable loaded ok
  3. Going to read /home/lb/.cpan/Metadata
  4.   Database was generated on Tue, 19 Sep 2006 23:33:30 GMT
  5. Running install for module IO::Socket::SSL
  6. Running make for S/SU/SULLR/IO-Socket-SSL-1.01.tar.gz
  7. CPAN: Digest::MD5 loaded ok
  8. Checksum for /home/lb/.cpan/sources/authors/id/S/SU/SULLR/IO-Socket-SSL-1.01.tar.gz ok
  9. IO-Socket-SSL-1.01/
  10. IO-Socket-SSL-1.01/example/
  11. IO-Socket-SSL-1.01/example/ssl_server.pl
  12. IO-Socket-SSL-1.01/example/ssl_client.pl
  13. IO-Socket-SSL-1.01/example/async_https_server.pl
  14. IO-Socket-SSL-1.01/Changes
  15. IO-Socket-SSL-1.01/certs/
  16. IO-Socket-SSL-1.01/certs/server-cert.pem
  17. IO-Socket-SSL-1.01/certs/server-key.enc
  18. IO-Socket-SSL-1.01/certs/client-key.enc
  19. IO-Socket-SSL-1.01/certs/server-key.pem
  20. IO-Socket-SSL-1.01/certs/client-key.pem
  21. IO-Socket-SSL-1.01/certs/test-ca.pem
  22. IO-Socket-SSL-1.01/certs/server-rsa384-dh.pem
  23. IO-Socket-SSL-1.01/certs/my-ca.pem
  24. IO-Socket-SSL-1.01/certs/client-cert.pem
  25. IO-Socket-SSL-1.01/t/
  26. IO-Socket-SSL-1.01/t/cert_no_file.t
  27. IO-Socket-SSL-1.01/t/core.t
  28. IO-Socket-SSL-1.01/t/dhe.t
  29. IO-Socket-SSL-1.01/t/02settings.t
  30. IO-Socket-SSL-1.01/t/compatibility.t
  31. IO-Socket-SSL-1.01/t/01loadmodule.t
  32. IO-Socket-SSL-1.01/t/sysread_write.t
  33. IO-Socket-SSL-1.01/t/ssl_settings.req
  34. IO-Socket-SSL-1.01/t/startssl.t
  35. IO-Socket-SSL-1.01/t/readline.t
  36. IO-Socket-SSL-1.01/t/nonblock.t
  37. IO-Socket-SSL-1.01/t/sessions.t
  38. IO-Socket-SSL-1.01/patches/
  39. IO-Socket-SSL-1.01/patches/Net_SSLeay.patch
  40. IO-Socket-SSL-1.01/MANIFEST
  41. IO-Socket-SSL-1.01/META.yml
  42. IO-Socket-SSL-1.01/SSL.pm
  43. IO-Socket-SSL-1.01/BUGS
  44. IO-Socket-SSL-1.01/docs/
  45. IO-Socket-SSL-1.01/docs/debugging.txt
  46. IO-Socket-SSL-1.01/util/
  47. IO-Socket-SSL-1.01/util/export_certs.pl
  48. IO-Socket-SSL-1.01/Makefile.PL
  49. IO-Socket-SSL-1.01/README
  50. Removing previously used /home/lb/.cpan/build/IO-Socket-SSL-1.01
  51.   CPAN.pm: Going to build S/SU/SULLR/IO-Socket-SSL-1.01.tar.gz
  52. Checking if your kit is complete...
  53. Looks good
  54. Warning: prerequisite Net::SSLeay 1.21 not found.
  55. Writing Makefile for IO::Socket::SSL
  56. ---- Unsatisfied dependencies detected during [S/SU/SULLR/IO-Socket-SSL-1.01.tar.gz] -----
  57.     Net::SSLeay
  58. Shall I follow them and prepend them to the queue
  59. of modules we are processing right now? [yes]
  60. Running make test
  61.   Delayed until after prerequisites
  62. Running make install
  63.   Delayed until after prerequisites
  64. Running install for module Net::SSLeay
  65. Running make for F/FL/FLORA/Net_SSLeay.pm-1.30.tar.gz
  66. Checksum for /home/lb/.cpan/sources/authors/id/F/FL/FLORA/Net_SSLeay.pm-1.30.tar.gz ok
  67. Net_SSLeay.pm-1.30/
  68. Net_SSLeay.pm-1.30/examples/
  69. Net_SSLeay.pm-1.30/examples/stdio_bulk.pl
  70. Net_SSLeay.pm-1.30/examples/ssl_diff.pl
  71. Net_SSLeay.pm-1.30/examples/ephemeral.pl
  72. Net_SSLeay.pm-1.30/examples/cb-testi.pl
  73. Net_SSLeay.pm-1.30/examples/req.conf
  74. Net_SSLeay.pm-1.30/examples/get_page_cert.pl
  75. Net_SSLeay.pm-1.30/examples/cli-cert.pl
  76. Net_SSLeay.pm-1.30/examples/sslcat.pl
  77. Net_SSLeay.pm-1.30/examples/get_authenticated_page.pl
  78. Net_SSLeay.pm-1.30/examples/https-proxy-snif.pl
  79. Net_SSLeay.pm-1.30/examples/callback.pl
  80. Net_SSLeay.pm-1.30/examples/bio.pl
  81. Net_SSLeay.pm-1.30/examples/ssl-inetd-serv.pl
  82. Net_SSLeay.pm-1.30/examples/sslecho.pl
  83. Net_SSLeay.pm-1.30/examples/get_page.pl
  84. Net_SSLeay.pm-1.30/examples/tcpecho.pl
  85. Net_SSLeay.pm-1.30/examples/passwd-cb.pl
  86. Net_SSLeay.pm-1.30/examples/tcpcat.pl
  87. Net_SSLeay.pm-1.30/examples/bulk.pl
  88. Net_SSLeay.pm-1.30/examples/server_key.pem
  89. Net_SSLeay.pm-1.30/examples/makecert.pl
  90. Net_SSLeay.pm-1.30/examples/minicli.pl
  91. Net_SSLeay.pm-1.30/ptrcasttst.c
  92. Net_SSLeay.pm-1.30/Net-SSLeay-Handle-0.50/
  93. Net_SSLeay.pm-1.30/Net-SSLeay-Handle-0.50/MANIFEST
  94. Net_SSLeay.pm-1.30/Net-SSLeay-Handle-0.50/Makefile.PL
  95. Net_SSLeay.pm-1.30/Net-SSLeay-Handle-0.50/test.pl
  96. Net_SSLeay.pm-1.30/Net-SSLeay-Handle-0.50/Changes
  97. Net_SSLeay.pm-1.30/Net-SSLeay-Handle-0.50/Handle.pm
  98. Net_SSLeay.pm-1.30/Changes
  99. Net_SSLeay.pm-1.30/MANIFEST
  100. Net_SSLeay.pm-1.30/typemap
  101. Net_SSLeay.pm-1.30/SSLeay.pm
  102. Net_SSLeay.pm-1.30/META.yml
  103. Net_SSLeay.pm-1.30/.rnd
  104. Net_SSLeay.pm-1.30/QuickRef
  105. Net_SSLeay.pm-1.30/RECIPE.Win32
  106. Net_SSLeay.pm-1.30/Credits
  107. Net_SSLeay.pm-1.30/test.pl
  108. Net_SSLeay.pm-1.30/SSLeay.xs
  109. Net_SSLeay.pm-1.30/README.Win32
  110. Net_SSLeay.pm-1.30/ptrtstrun.pl
  111. Net_SSLeay.pm-1.30/README
  112. Net_SSLeay.pm-1.30/Makefile.PL
  113. Removing previously used /home/lb/.cpan/build/Net_SSLeay.pm-1.30
  114.   CPAN.pm: Going to build F/FL/FLORA/Net_SSLeay.pm-1.30.tar.gz
  115. Checking for OpenSSL-0.9.6j or 0.9.7b or newer...
  116. I could not find your OpenSSL in `INSTALLDIRS=site'
  117. Please provide OpenSSL-0.9.6j or
  118. OpenSSL-0.9.7b installation directory (get from
  119. http://www.openssl.org/ if you don't have it; please note that
  120. SSLeay is no longer supported, see README) (C-c to abort):
  121. Running make test
  122.   Make had some problems, maybe interrupted? Won't test
  123. Running make install
  124.   Make had some problems, maybe interrupted? Won't install
  125. Running make for S/SU/SULLR/IO-Socket-SSL-1.01.tar.gz
  126.   Is already unwrapped into directory /home/lb/.cpan/build/IO-Socket-SSL-1.01
  127.   CPAN.pm: Going to build S/SU/SULLR/IO-Socket-SSL-1.01.tar.gz
  128. cp SSL.pm blib/lib/IO/Socket/SSL.pm
  129. Manifying blib/man3/IO::Socket::SSL.3pm
  130.   /usr/bin/make  -- OK
  131. Running make test
  132. PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
  133. t/01loadmodule.....Can't locate Net/SSLeay.pm in @INC (@INC contains: /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/arch /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib/IO/Socket/SSL.pm line 17.
  134. BEGIN failed--compilation aborted at /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib/IO/Socket/SSL.pm line 17.
  135. Compilation failed in require at t/01loadmodule.t line 11.
  136. BEGIN failed--compilation aborted at t/01loadmodule.t line 11.
  137. t/01loadmodule.....dubious
  138.         Test returned status 2 (wstat 512, 0x200)
  139. DIED. FAILED tests 1-4
  140.         Failed 4/4 tests, 0.00% okay
  141. t/02settings.......Can't locate Net/SSLeay.pm in @INC (@INC contains: /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/arch /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib/IO/Socket/SSL.pm line 17.
  142. BEGIN failed--compilation aborted at /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib/IO/Socket/SSL.pm line 17.
  143. Compilation failed in require at t/02settings.t line 4.
  144. BEGIN failed--compilation aborted at t/02settings.t line 4.
  145. t/02settings.......dubious
  146.         Test returned status 2 (wstat 512, 0x200)
  147. t/cert_no_file.....Can't locate Net/SSLeay.pm in @INC (@INC contains: /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/arch /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at t/cert_no_file.t line 14.
  148. BEGIN failed--compilation aborted at t/cert_no_file.t line 14.
  149. t/cert_no_file.....dubious
  150.         Test returned status 2 (wstat 512, 0x200)
  151. t/compatibility....Can't locate Net/SSLeay.pm in @INC (@INC contains: /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/arch /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib/IO/Socket/SSL.pm line 17.
  152. BEGIN failed--compilation aborted at /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib/IO/Socket/SSL.pm line 17.
  153. Compilation failed in require at t/compatibility.t line 5.
  154. BEGIN failed--compilation aborted at t/compatibility.t line 5.
  155. t/compatibility....dubious
  156.         Test returned status 2 (wstat 512, 0x200)
  157. t/core.............Can't locate Net/SSLeay.pm in @INC (@INC contains: /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/arch /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at t/core.t line 6.
  158. BEGIN failed--compilation aborted at t/core.t line 6.
  159. t/core.............dubious
  160.         Test returned status 2 (wstat 512, 0x200)
  161. t/dhe..............Can't locate Net/SSLeay.pm in @INC (@INC contains: /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/arch /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at t/dhe.t line 11.
  162. BEGIN failed--compilation aborted at t/dhe.t line 11.
  163. t/dhe..............dubious
  164.         Test returned status 2 (wstat 512, 0x200)
  165. t/nonblock.........Can't locate Net/SSLeay.pm in @INC (@INC contains: /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/arch /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at t/nonblock.t line 6.
  166. BEGIN failed--compilation aborted at t/nonblock.t line 6.
  167. t/nonblock.........dubious
  168.         Test returned status 2 (wstat 512, 0x200)
  169. t/readline.........Can't locate Net/SSLeay.pm in @INC (@INC contains: /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/arch /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at t/readline.t line 14.
  170. BEGIN failed--compilation aborted at t/readline.t line 14.
  171. t/readline.........dubious
  172.         Test returned status 2 (wstat 512, 0x200)
  173. t/sessions.........Can't locate Net/SSLeay.pm in @INC (@INC contains: /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/arch /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at t/sessions.t line 5.
  174. BEGIN failed--compilation aborted at t/sessions.t line 5.
  175. t/sessions.........dubious
  176.         Test returned status 2 (wstat 512, 0x200)
  177. t/startssl.........Can't locate Net/SSLeay.pm in @INC (@INC contains: /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/arch /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at t/startssl.t line 6.
  178. BEGIN failed--compilation aborted at t/startssl.t line 6.
  179. t/startssl.........dubious
  180.         Test returned status 2 (wstat 512, 0x200)
  181. t/sysread_write....Can't locate Net/SSLeay.pm in @INC (@INC contains: /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/lib /home/lb/.cpan/build/IO-Socket-SSL-1.01/blib/arch /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at t/sysread_write.t line 9.
  182. BEGIN failed--compilation aborted at t/sysread_write.t line 9.
  183. t/sysread_write....dubious
  184.         Test returned status 2 (wstat 512, 0x200)
  185. Failed Test       Stat Wstat Total Fail  Failed  List of Failed
  186. -------------------------------------------------------------------------------
  187. t/01loadmodule.t     2   512     4    8 200.00%  1-4
  188. t/02settings.t       2   512    ??   ??       %  ??
  189. t/cert_no_file.t     2   512    ??   ??       %  ??
  190. t/compatibility.t    2   512    ??   ??       %  ??
  191. t/core.t             2   512    ??   ??       %  ??
  192. t/dhe.t              2   512    ??   ??       %  ??
  193. t/nonblock.t         2   512    ??   ??       %  ??
  194. t/readline.t         2   512    ??   ??       %  ??
  195. t/sessions.t         2   512    ??   ??       %  ??
  196. t/startssl.t         2   512    ??   ??       %  ??
  197. t/sysread_write.t    2   512    ??   ??       %  ??
  198. Failed 11/11 test scripts, 0.00% okay. 4/4 subtests failed, 0.00% okay.
  199. make: *** [test_dynamic] 错误 2
  200.   /usr/bin/make test -- NOT OK
  201. Running make install
  202.   make test had returned bad status, won't install without force
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-22 01:37:50 | 显示全部楼层
Post by DonkeyJml
注意看出错信息
上CPAN搜 Mail:OP3Client 然后装之

我去cpan上下了IO::Socket::SSL,费了好在劲才装上,可是运行还是出现错误
怎么办?我对perl一窍不通的......
  1. ./gmail.pl
  2. Can't locate IO/Socket/SSL.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at ./gmail.pl line 32.
  3. BEGIN failed--compilation aborted at ./gmail.pl line 32.
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-9-22 03:00:51 | 显示全部楼层
你的 openssl 没装 -dev  或者 -devel 包吧。。。具体安装参考你的发行版的相关文章。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表