Hi,

I'm trying to add the symbol '#' in the /etc/services file for disabling the
following services:
ftp
chargen
daytime

I've placed the name of the services i.e ftp, chargen, daytime into a text
file to be read by the script. This is because there are many other services
to be disabled from the /etc/services file.The script is written as follows:

#!/usr/bin/perl

$inputFile = "/home/cs/pattern";
open(INPUT, "$inputFile");
close(INPUT);
$servicesFile ="/etc/services";
open(SERVICES, "$servicesFile");
close(SERVICES);

@fileEntries = <INPUT>;    # reads input file entries
@servicesEntries = <SERVICES>  #reads entries from /etc/services.
foreach $i (@fileEntries) {
        foreach $j (@serviceEntries){
               if(fileEntries[$i] eq serviceEntries[$j]) {
                              system("sed 's/^/\# \ //g' ");   #adds "#" at
the beginning of the patterns such as ftp, chargen and daytime in
/etc/services file. 
           }            
        }     
}

However, the script did not add the "#" symbol in the /etc/services file
when it encountered the patterns such ftp, chargen or daytime when reading
from the input text file.

I've also tried replacing the statement system("sed 's/^/\# \ //g' ") to the
one below:
system("awk ' \{print "# $0\}' "), which did not work too.    

Could someone show me how it should be done? I'm rather new to PERL.

Also, how do I write a PERL condition which checks if there is no "#" at the
beginning of patterns ftp, chargen, and daytime, then insert the "#" at the
beginning. Else, proceed to the next pattern. 

Could someone help me out?

Thanks.






 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to