文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Perl语言入门笔记:第十四天

Perl语言入门笔记:第十四天

时间:2010-09-06  来源:linscora

今天就写了一个自动安装squid的perl脚本,遇到了很多问题,也明白了很多!   squid的参数只改了一部分。因为还没有学到控制结构,所以没有用判断语句,慢   慢改进。   今天测了最久就也就是文件句柄那里了。所以我也写点文件句柄的内容:   1、文件前面没有">"表示读文件。 [server1@root perl]# cat open1
#!/usr/bin/perl -w
open (CONFIGFILE, '/etc/inittab');
while (<CONFIGFILE>) {
chomp;
print "$_\n";
}
close CONFIGFILE;
这里就写/etc/inittab这个文件的内容打印到了屏幕上。
  2、文件前面有一个">"表示写文件,并覆盖原有内容。 open (CONFIGFILE, '>/etc/inittab');
print CONFIGFILE "linscora";
close CONFIGFILE;
  3、用两个">>"表是追加。  

#!/usr/bin/perl -w

my $squidfile='./squid-3.0.STABLE24.tar.gz';
system("tar -zxvf $squidfile");
#system("cd squid-3.0.STABLE24");

system("./squid-3.0.STABLE24/configure --prefix=/usr/local/squid2 --enable-storeio=aufs,diskd,ufs");
system("make");
system("make install");

#init file

my $squidconf='/usr/local/squid2/etc/squid.conf';
system("mkdir -p /var/log/squid");
system("useradd -s /sbin/nologin squid");
system("mkdir /cache1 /cache2");
system("chown -R squid /var/log/squid");
system("chown -R squid /cache1 /cache2");
system("cp /usr/local/squid2/etc/squid.conf{,.bak}");

#chage config files

use strict;
use IO::File;
my $CONFIG;
my $a;
open $CONFIG, '<', '/usr/local/squid2/etc/squid.conf'
      or die "Could not open this file: $!";
open $a, ">>", '/usr/local/squid2/etc/squid.conf.orig'
        or die "Could not open this file: $!";
select $a;
while (<$CONFIG>) {
#chomp;

s/#\s*TAG:\s*visible_hostname/visible_hostname linscora/;

s/^access_log.*/access_log \/var\/log\/squid\/access.log squid/;
s/# cache_log.*/cache_log \/var\/log\/squid\/cache.log squid/;

s/# cache_effective_user\snobody/cache_effective_user squid/;

s/# cache_effective_group\snobody/cache_effective_group squid/;

s/^# cache_dir.*/cache_dir aufs \/cache1 18432 16 256/;

s/^icp_port.*/icp_port 0/;
s/# cache_mem.*/cache_mem 768 MB/;

s/# cache_swap_low.*/cache_swap_low 85 MB/;

s/# cache_swap_high.*/cache_swap_high 90 MB/;

s/# cache_store_log.*/cache_store_log none/;

print "$_";
}
close $CONFIG;
close $a;
system("yes|cp /usr/local/squid2/etc/squid.conf.orig /usr/local/squid2/etc/squid.conf");


相关阅读 更多 +
排行榜 更多 +
谷歌卫星地图免费版下载

谷歌卫星地图免费版下载

生活实用 下载
谷歌卫星地图免费版下载

谷歌卫星地图免费版下载

生活实用 下载
kingsofpool官方正版下载

kingsofpool官方正版下载

赛车竞速 下载