need help executing a script that someone sent me
I'm working on adding the MVP hots file to the black list on my IPCop box. I use URL Filter addon, and I contacted the author, and he sent me a script with these instructions.
Quote:
This is the command that I used, but I probably did it wrong ./tmp/mvphosts2blacklist /tmp/HOSTS It says run this script with the name of the hosts file as the first command line argument, but I have no idea what that means. |
First read the file to make sure it doesn't do anything bad.
You probably are supposed to run: sudo /tmp/mvphosts2blacklisat /etc/hosts. I'm guessing that it has domain/ip address pairs which redirects queries to your local host address 127.0.0.1. The host files is checked before a nameserver. |
Some questions:
1) You have a ./ at the beginning of your command - is that just a typo here? 2) Where did you get the file /tmp/HOSTS ? Is that your /etc/hosts file ? 3) Were you root (or admin) on the system when you ran the command ? |
On second thought, IPcop may have a blacklist file, and that may be what you are supposed to use as the argument.
|
Sorry, I started entering in another host and must have bumped the "go back on page" somehow. Please ignore.
|
The script is suppose to modify the URL Filter plugin. The host file comes from here
http://www.mvps.org/winhelp2002/hosts.htm Its basically a black list of bad stuff, and I just want to ad it to the Black list in URL Filter Yes the host file is made to redirect to 127.0.0.1, but it looks like the script removes this and the comments to make it suitable for the black list. The guy who wrote the script is the author of the URL Filter plugin. I trust that there isn't anything bad in it. Should I post the script? 1) no ./ was not a typo, I know very little about linux command line. Next to nothing. I just started doing a little bit when adding addons to my IPCop box. 2)I linked to where I got the host file above 3)yes I was root when I tried to do this Basically I just don't know how to do this Quote:
|
A couple of explainations. A script needs to have the "x" bit set to run it by name. Second, the "current working directory" (.) isn't in your path by default. If you want to run a script in the directory you are in, then you precede the name with "./" which includes the relative location of the script. If this script is in the /tmp directory and you are in the /tmp directory, then ./<scriptname> will run it as well as /tmp/<scriptname> which uses an absolute pathname.
Since you are in the /tmp directory, check the output of "mount" which lists how partitions are mounted. If /tmp is mounted on its own partition, and you see the option "noexec", then you can't run a script in /tmp directly. You can however run it like "sh <scriptname>" for a bash script. ( note: look at the first line of the script. If it says "#!/bin/bash" or "#!/bin/sh" then it is a bash script. If it says "#!/usr/bin/perl" then it is a perl script. You get the idea. The first line contains a "sha bang" comment that gives the location of the interpreter, such as sh, bash, perl, python, etc. that the kernel launches to run the script. Again, this is just needed if the /tmp directory is on a partition mounted with the noexec option. If you read the script is may have comments explaining what this "hosts" file is that you need to include as an argument. If the author doesn't mean /etc/hosts, then he may not have chosen the best term in the instructions. He may mean the current blacklist file, but I couldn't guarantee that. The comments in the script may make clear what is wanted even though the file will be refered to in the script by the ${1} argument. If the script is merging entries from the file given in the argument and creating a new file, the file it creates may be an updated version of the file it wants. You may want to make a copy of the original and save it in /tmp and use that file as the argument, just in case you made a mistake. |
I don't have to run it from a tmp directory. In fact I just created a directory named tmp to work in. I was trying to do this from the root directory also. Here is te script
#!/usr/bin/perl # # This code is distributed under the terms of the GPL # # (c) 2008 marco.s - http://www.urlfiter.net # # $Id: mvphosts2blacklist,v 1.0 2008/08/10 00:00:00 marco.s Exp $ # use strict; use Getopt::Std; my $swroot="/var/ipcop"; my $dbdir="$swroot/urlfilter/blacklists"; my $executable=substr($0,rindex($0,"/")+1,length($0)); getopts(''); unless (-T $ARGV[0]) { &HELP_MESSAGE; exit; } unless (-d "$dbdir/mvphosts") { mkdir "$dbdir/mvphosts"; } open (INFILE,$ARGV[0]); open (OUTFILE,">$dbdir/mvphosts/domains"); while (<INFILE>) { s/127\.0\.0\.1\s+//g; s/#.*//g; s/^\s+//g; s/\s+$//g; if ($_) { print OUTFILE "$_\n"; } } close INFILE; close OUTFILE; open (CONFIG,">/tmp/mvphosts.conf"); print CONFIG <<END dbhome $dbdir dest mvphosts { domainlist mvphosts/domains } acl { default { pass none } } END ; close CONFIG; if (-e "$dbdir/mvphosts/domains") { system ("/usr/sbin/squidGuard -d -c /tmp/mvphosts.conf -C $dbdir/mvphosts/domains"); } unlink ("/tmp/mvphosts.conf"); system ("chown -R nobody:nobody $dbdir/mvphosts"); if (-e "$dbdir/mvphosts/domains.db") { system ("chmod 666 $dbdir/mvphosts/domains.db"); } # ------------------------------------------------------------------- sub VERSION_MESSAGE { $Getopt::Std::STANDARD_HELP_VERSION=1; print <<EOM $executable (URLfilter coreutils) 1.00 Copyright (c) 2008 marco.s - http://www.urlfilter.net EOM ; } # ------------------------------------------------------------------- sub HELP_MESSAGE { print <<EOM Usage: $executable FILE Converts FILE into a blacklist named mvphosts FILE must be a hostfile from mvps.org (http://www.mvps.org/winhelp2002/hosts.htm) --help display this help --version output version information EOM ; } # ------------------------------------------------------------------- |
This looks like it just takes host table entries (see /etc/hosts) and strips everything but the FQDN.
The script is taking long, serially scanned lists of hosts mappted to 127.0.0.1 and adding them into a faster database mechanmism. So, if you have a large /etc/hosts file filled with loads of mappings to 127.0.0.1, run the script on a copy of your /etc/hosts file. It just reads the file, so it is save to use /etc/hosts as the argument. |
Honestly guys. I don't want to sound stupid, and I do understand a lot of what you guys are saying, but I'm not getting it all. One of the things that I noticed was that when I used just /mvphosts2blacklist it would give me an error saying that no file or folder was found. So would it help to use a command more like /tmp/mvphosts2blacklist.perl /tmp/url.txt?
|
No, just use the name of the program as is.
|
Thank you. My question still hasn't been answered, or at least answered in a way that I can understand.
|
Log on as root on your IPCop system.
Grab the hosts file from the URL you provided to us. Save it as /tmp/hosts. Find the script you were given. Run: perl /fullpath/to/your/script /tmp/hosts Thats it. |
Got the same results as before. I just get this message
Converts FILE into a blacklist named mvphosts FILE must be a hostfile from mvps.org (http://www.mvps.org/winhelp2002/hosts.htm) --help display this help --version output version information And nothing changes. I think the problem may be something other than the way I am executing the script. I'll contact Marco Sondermann about it. Thanks for the help |
The help message is output if the script thinks your file is not ASCII. So let's assume your command line was correct. In this case, the file probably has the wrong end of line characters. Run
dos2unix /tmp/hosts and then try again. If you don't have dos2unix, you can use vim /tmp/hosts with the command: :set ff=unix :wq and then rerun the commmand. If this fails, please show the exact command you used. |
All times are GMT -5. The time now is 12:57 PM. |