Gossamer Forum
Home : Products : Gossamer Links : Discussions :

How do I mass delete bad links

Quote Reply
How do I mass delete bad links
Hi,

I ran a verify from Telnet which took about 14 hours to complete, thankfully it is done now but I have got several thousand bad links to prune out. How can I mass delete these.

The interface seems to lead me down the route of selecting each one on a page of about 20 at a time and deleting them but this will take me eons, is there a way to simply delete all bad links with codes 401, 400, 403, 201 etc from my links sql panel.

Also i have got a DMOZ dump file sitting on my server, it's a big monster, can i delete this after running Andy's DMOZ import script.

Thanks

Kevin

Cheers
KevM
Quote Reply
Re: [KevM] How do I mass delete bad links In reply to
Hi. You could try making a new script (something like delete_bad.cgi), and put the following in it;

Code:
#!/usr/bin/perl

use strict;
use lib './';
use Links qw/$IN $DB $CFG/;
use GT::SQL;
use GT::SQL::Condition;
use CGI::Carp qw(fatalsToBrowser);

local $SIG{__DIE__} = \&Links::fatal;

Links::init('./');

print $IN->header();

# first of all, lets actually get rid of all the categories...
my @links_list;
my $table = $DB->table('Links');
my @error_codes = qw(404 401 204 403 -4 -6 -8 -5 503 400 500);

foreach (@error_codes) {
print "Code checking $_ \n";
my $sth = $table->select( { Status => "$_" } ) || die $GT::SQL::error;
while (my $hit = $sth->fetchrow_hashref) {
push(@links_list,"$hit->{ID}::$hit->{Status}");
}
}

foreach (@links_list) {
my @sli = split("::",$_);
print "Deleting $sli[0] (code $sli[1]) \n";
$table->delete( { ID => $sli[0] } ) or die $GT::SQL::error;
}

This needs to be in the /admin folder; and can then be run from SSH with perl delete_bad.cgi, and it should delete all links that have a status code (defined in @error_codes).

Anyone reading this in the future, please note, this DOES require you to run a "Verify" before (with nph-verify.cgi), or else the script won't know what to pick up :)

Quote:
Also i have got a DMOZ dump file sitting on my server, it's a big monster, can i delete this after running Andy's DMOZ import script.

Yeah, you should be safe to delete the *.dump and *.dump.slice files, as well as the content.rdf.u8 file :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] How do I mass delete bad links In reply to
what a nice bloke,

cheers Andy just doing a full rebuild now but it appears to have worked a treat!

Smile

Cheers
KevM
Quote Reply
Re: [KevM] How do I mass delete bad links In reply to
In Reply To:
what a nice bloke,

cheers Andy just doing a full rebuild now but it appears to have worked a treat!

Smile

Glad to hear it :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] How do I mass delete bad links In reply to
Hi I did run the Verify Links from the administrator area and I have about 8000 bad links. I did tried this script and I run it from SSH, but it doesn’t work. Is that because I didn’t run the Verify Links from SSH? I can see all my bad links in the Link Status, but I cannot delete them using this script. Any ideas?

Thanks

MIRO
Quote Reply
Re: [modifier] How do I mass delete bad links In reply to
Hi,

This should work. It will find all of the following error codes;

Quote:
404
401
204
403
-4
-6
-8
-5
503
400
500

How are you running the script via SSH? (i.e the command).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] How do I mass delete bad links In reply to
Here is an error I see in my SSH client when I try to run the “delete_bad.cgi”

dmoz@east admin $ perl delete_bad.cgi

Content-type: text/html

Code checking 404
<p><font face='Tahoma,Arial,Helvetica' size=2>A fatal error has occured:</font></p><blockquote><pre>Can't locate /GT/SQL/Driver/MYSQL.pm in @INC (@INC contains: ./ /etc/perl /usr/lib/perl5/site_perl/5.8.3/i686-linux /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.3/i686-linux /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.3/i686-linux /usr/lib/perl5/5.8.3 /usr/local/lib/site_perl /usr/lib/gpanel .) at /GT/SQL/Driver.pm line 71.
</pre></blockquote><p><font face='Tahoma,Arial,Helvetica' size=2>Please enable debugging in setup for more details.</font></p>
Can't locate /GT/SQL/Driver/MYSQL.pm in @INC (@INC contains: ./ /etc/perl /usr/lib/perl5/site_perl/5.8.3/i686-linux /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.3/i686-linux /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.3/i686-linux /usr/lib/perl5/5.8.3 /usr/local/lib/site_perl /usr/lib/gpanel .) at /GT/SQL/Driver.pm line 71.
dmoz@east admin $

Any suggestions?

Thanks


MIRO

Last edited by:

modifier: Mar 17, 2005, 3:20 PM
Quote Reply
Re: [modifier] How do I mass delete bad links In reply to
Did you change the paths?

use lib './';

Links::init('./');

They need to look something like;

Links::init('/full/path/to/admin');

Otherwise, are you running a Plesk server?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!