今天就写了一个自动安装squid的perl脚本,遇到了很多问题,也明白了很多!
squid的参数只改了一部分。因为还没有学到控制结构,所以没有用判断语句,慢
慢改进。
今天测了最久就也就是文件句柄那里了。所以我也写点文件句柄的内容:
1、文件前面没有">"表示读文件。
[server1@root perl]# cat open1
#!/usr/bin/perl -w
open (CONFIGFILE, '/etc/inittab');
while () {
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");
|
阅读(715) | 评论(0) | 转发(0) |