Monks,
I have this little script that I'm using to disable unneeded services in Linux. It works fine the first time around, but when I run it again, say because I added a new service, it moves all of the other files like so:
.NO..NO.K74apmd
I thought my regex would not match on a .NO, so I'm not sure what's wrong. What should I do to make sure it won't match anything with a .NO in front of it? I haven't been coding much lately so please be kind if it's really obvious :-)
#!/usr/bin/perl -w
use strict;
# Script used to disable services that are not needed
my @dirs = qw(rc0 rc1 rc2 rc3 rc4 rc5 rc6);
my $expression = "autofs|apmd|isdn|lpd|netfs|nfs|nfslock|nscd|portmap
|radvd|rstatd|rusersd|rwalld|rwhod|sendmail|ypbind|yppasswd|ypserv
|ypxfrd";
my $result;
my $i;
for $i (@dirs){
opendir (DIR, "/etc/$i.d") or die "Can't open directory $_\n";
while (my $name = readdir(DIR)){
my $cmd1 = "/bin/mv /etc/$i.d/$name /etc/$i.d/.NO.$name" or print
"/etc/$i.d/$name not found\n";
`$cmd1` if $name =~ /\b(K|S)\d{2}?$expression\b/;
}
closedir DIR;
}
Thanks,
Dru
Another satisfied monk.