LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-11-2008, 11:03 PM   #1
giantjoebot
Member
 
Registered: Mar 2006
Posts: 43

Rep: Reputation: 15
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:
Copy this script to your IPCop and change the attributes to rwxr-xr-x

chmod 755 mvphosts2blacklist

Now copy the hosts file to your IPCop and run this script with the name of the hosts file as the first command line argument, e.g.
/tmp/mvphosts2blacklist /tmp/url.txt

After a few seconds you will find a new blacklist category "mvphosts".

This is much better than adding the contents to the custom blacklist. The
custom blacklist is not optimized for speed (it's ASCII and not a database
than all other categories) and therefore a bigger custom blacklist may slow
down your IPCop.

Marco Sondermann
So I changed the permissions of the script just fine, but I can't seem to be able to run the script properly because nothing is changing like its suppose to.

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.
 
Old 08-11-2008, 11:19 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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.
 
Old 08-11-2008, 11:20 PM   #3
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
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 ?
 
Old 08-11-2008, 11:22 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
On second thought, IPcop may have a blacklist file, and that may be what you are supposed to use as the argument.
 
Old 08-11-2008, 11:31 PM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Sorry, I started entering in another host and must have bumped the "go back on page" somehow. Please ignore.

Last edited by jschiwal; 08-11-2008 at 11:32 PM.
 
Old 08-11-2008, 11:50 PM   #6
giantjoebot
Member
 
Registered: Mar 2006
Posts: 43

Original Poster
Rep: Reputation: 15
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:
run this script with the name of the hosts file as the first command line argument, e.g.
/tmp/mvphosts2blacklist /tmp/url.txt

Last edited by giantjoebot; 08-11-2008 at 11:57 PM.
 
Old 08-12-2008, 12:18 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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.
 
Old 08-12-2008, 12:27 AM   #8
giantjoebot
Member
 
Registered: Mar 2006
Posts: 43

Original Poster
Rep: Reputation: 15
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
;
}

# -------------------------------------------------------------------
 
Old 08-12-2008, 12:47 AM   #9
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
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.
 
Old 08-12-2008, 03:26 AM   #10
giantjoebot
Member
 
Registered: Mar 2006
Posts: 43

Original Poster
Rep: Reputation: 15
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?
 
Old 08-12-2008, 03:31 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,374

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
No, just use the name of the program as is.
 
Old 08-12-2008, 07:58 PM   #12
giantjoebot
Member
 
Registered: Mar 2006
Posts: 43

Original Poster
Rep: Reputation: 15
Thank you. My question still hasn't been answered, or at least answered in a way that I can understand.
 
Old 08-12-2008, 08:05 PM   #13
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
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.
 
Old 08-12-2008, 11:56 PM   #14
giantjoebot
Member
 
Registered: Mar 2006
Posts: 43

Original Poster
Rep: Reputation: 15
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
 
Old 08-13-2008, 12:10 AM   #15
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sh script not executing as expected ryzor Linux - General 4 12-18-2006 09:03 AM
Bash script - executing a script through subdirectories bubkus_jones Programming 5 04-24-2006 05:05 PM
executing a script!! vishamr2000 Linux - Security 5 07-29-2005 02:34 AM
Executing install script for ... securehack Linux - Software 6 05-24-2005 11:02 AM
Script is not executing in Apache!!! linux_child001 Linux - Newbie 1 06-22-2004 05:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration