Front page
Archive
Silflay Hraka?


Bigwig is a systems administrator at a public university
Hrairoo is the proprietor of a quality used bookstore
Kehaar is.
Woundwort is a professor of counseling at a private university

The Hraka RSS feed

Email
bigwig AT nc.rr.com

Friends of Hraka
InstaPundit
Daily Pundit
cut on the bias
Meryl Yourish
This Blog Is Full Of Crap
Winds of Change
A Small Victory
Silent Running
Dr. Weevil
Little Green Footballs
ColdFury
Oceanguy
Fragments from Floyd
VodkaPundit
Allah
The Feces Flinging Monkey
Dean's World
Little Tiny Lies
The Redsugar Muse
Sperari
Natalie Solent
From the Mrs.
ErosBlog
The Anti-Idiotarian Rottweiler
On the Third Hand
Public Nuisance
Not a Fish
Rantburg
AMCGLTD
WeckUpToThees!
Electric Venom
Skippy, The Bush Kangaroo
Common Sense and Wonder
Neither Here Nor There
Wizbang!
Bogieblog
ObscuroRant
RocketJones
The Greatest Jeneration
Ravenwolf
Ipse Dixit
TarHeelPundit
Blog On the Run
blogatron
Redwood Dragon
Notables
Greeblie Blog
Have A Cuppa Tea
A Dog's Life
IMAO
Zonitics.com
Iberian Notes
Midwest Conservative Journal
A Voyage to Arcturus
HokiePundit
Trojan Horseshoes
In Context
dcthornton.blog
The People's Republic of Seabrook
Country Store
Blog Critics
Chicago Boyz
Hippy Hill News
Kyle Still Free Press
The Devil's Excrement
The Fat Guy
War Liberal
Assume the Position
Balloon Juice
Iron Pen In A Velvet Glove
IsraPundit
Freedom Lives
Where Worlds Collide
Knot by Numbers
How Appealing
South Knox Bubba
Heretical Ideas
The Kitchen Cabinet
Dustbury.com
tonecluster
Bo Cowgill
mtpolitics.net
Raving Atheist
The Short Strange Trip
Shark Blog
Hoplites
Jimspot
Ron Bailey's Weblog
Cornfield Commentary
Testify!
Northwest Notes
pseudorandom
The Blog from the Core
Ain'tNoBadDude
CroMagnon
The Talking Dog
WTF Is It Now??
Blue Streak
Smarter Harper's Index
nikita demosthenes
Bloviating Inanities
Sneakeasy's Joint
Ravenwood's Universe
The Eleven Day Empire
World Wide Rant
All American
Pdawwg
The Rant
The Johnny Bacardi Show
The Head Heeb
Viking Pundit
Mercurial
Oscar Jr. Was Here
Just Some Poor Schmuck
Katy & Bruce Loebrich
But How's The Coffee?
Roscoe Ellis
Foolsblog
Sasha Castel
Dodgeblogium
Susskins Central Dispatch
DoggerelPundit
Josh Heit
Attaboy
Aaron's Rantblog
MojoMark
As I was saying...
Blog O' Dob
Dr. Frank's Blogs Of War
Betsy's Page
A Knob for Brightness
Fresh Bilge
The Politburo Diktat
Drumwaster's rants
Curt's Page
The Razor
An Unsealed Room
The Legal Bean
Helloooo chapter two!
As I Was Saying...
SkeptiLog AGOG!
Tong family blog
Vox Beth
Velociblog
I was thinking
Judicious Asininity
This Woman's Work
Fragrant Lotus
DaGoddess
Single Southern Guy
Caerdroia
GrahamLester.Com
Jay Solo's Verbosity
TacJammer
Snooze Button Dreams
Horologium
You Big Mouth, You!
From the Inside looking Out
Night of the Lepus
No Watermelons Allowed
From The Inside Looking Out
Lies, Damn Lies, and Statistics
Suburban Blight
Aimless
The SmarterCop
Dog of Flanders
From Behind the Wall of Sleep
Beaker's Corner
Bad State of Gruntledness
Who Tends The Fires
Granny Rant
Elegance Against Ignorance
Moxie.nu
Eccentricity
Say What?
Blown Fuse
Wait 'til Next Year
The Pryhills
The Whomping Willow
The National Debate
The Skeptician
Zach Everson
MonkeyWatch
Geekward Ho
Argghhh!!!
Life in New Orleans
Rotten Miracles
Fringe
The Biomes Blog
illinigirl
See What You Share
Truthprobe
Blog d’Elisson
Your Philosophy Sucks
Watauga Rambler
Socialized Medicine
Consternations
Verging on Pertinence
Read My Lips
ambivablog
Soccerdad
The Flannel Avenger
Butch Howard's WebLog
Castle Argghhh!
Andrew Hofer
kschlenker.com
Moron Abroad
White Pebble
Darn Floor
Wizblog
tweedler
Pajama Pundits
BabyTrollBlog
Cadmusings
Goddess Training 101
A & W
Medical Madhouse
Slowly Going Sane
The Oubliette
American Future
Right Side Redux
See The Donkey
Newbie Trucker
The Right Scale
Running Scared
Ramblings Journal
Focus On Reality
Wyatt's Torch

October 23, 2003

Replacing Text in Multiple Files

Ok, I think I've finally restored Hraka, as well as FDS and The Warren, to their full functionality. The last remaining obstacle to this was the commenting function, which worked fine unless one happened to be accessing comments via one of the category archives, such as Unseen History or Demon Liquor.

Essentially what happened is once upon a time, just after I moved the site off blogspot, the url "silflayhraka.com" didn't really exist yet. For the first couple of days of the new blog's existance, anyone or anything who wanted to get here had to use the IP address Silflay had been assigned, 63.247.131.116. This included the Movable Type application I was using to publish to the site. I never bothered to change it once it was no longer necessary to use the IP address, since by then "63.247.131.116" and "silflayhraka.com" meant the same thing anyway.

But when Hosting Matters moved Silflay off of that IP address, due to the presumed jihadi DoS attacks, the site was crippled. Publishing and commenting were especially affected. At one point, before I figured out what was going on, I was having to rebuild the entire site each time I wanted to publish a new post.

A couple of config changes restored 90% of the functionality, but the last 10% was the hard part. There are over 3000 separate html and xml files on the site, and damn near every one of them had a reference to http://63.247.131.116/ instead of http://Silflayhraka.com somewhere in the code, usually multiple times

Now there's no way I was going to replace every single one of those instances by hand, so I started writing a shell script to do it for me. I never finished it, as I can across this Dean Mah perl script after a quick Google on multiple file text replacement.

If you need to use it, don't do a direct cut and paste of the code, at least not into a vi session. There are a couple of windows characters and some odd HTML escapes in there that will trip you up. Here's what it looked like for me once I fixed those.

#!/usr/bin/perl

#
# Replaces a string within multiple files
# specified on the command line

$mv = '/bin/mv';

$op = shift || die("Usage: $0 perlexpr [filenames]\n");

if (!@ARGV) {
@ARGV = ;
chop(@ARGV);
}

foreach $file (@ARGV) {
if (!-f $file) { print "Skipping non-regular file: $file\n" ;; next; }
if (-B $file) { print "Skipping binary file: $file\n"; next; }

$outfile = "/usr/tmp/$file.$$";

open(FILE, $file) || die "Couldnt open $file: $!\n" ;
undef $/;
$_ = ;
close(FILE);

if (eval $op) {
open(OFILE, "> $outfile") || die("Couldn't open $outfile: $!\n");
print OFILE;
close(OFILE);

system($mv, '-f', $file, "$file.bak");
system($mv, '-f', $outfile, $file);

print "File changed: $file\n";
}
else {
print "No change to file: $file\n";
}
}

exit(0);

Note that a couple of paths have also changed. That's a reflection of the local quirks of the Hosting matters server I ran it on. You should also know that Hosting Matters already has a program called "replace" running on its servers, so you'll need to name the file something other than that if you want to use it on one of their boxes. I called mine "hrakareplace", calling it via the command line like this.

$ hrakareplace 's/63\.247\.131\.116/silflayhraka\.com/g' *.html

The backslashes are there to let the program know that what follows immediately afterwards is an actual period rather than a wild card that represents something else.

The "*.html" is there to let the program know to do the replacement in every file that ends in a .html extension. Make sure you have enough space on the server allocated to you before running the program with that argument! Say, at least double whatever it is at present. If you don't know, don't run it.

I can say this becuase I did not know, and ended up with a bunch of empty files where there used to be deathless prose when the program ran into the space wall at high speed. Fortunately Hosting Matters runs a nightly backup, so the Hraka archives were back up after an hour or so. The hour wait was enough to wear down the fingernails to nubs, though.

Now, I jest need someone to point out how this could have been done via the command line rather than a Perl script, and my day will be complete.

Posted by Bigwig at October 23, 2003 02:42 PM | TrackBack
Postscript:
First time visitor to House Hraka? Wondering if everything we produce could possibly be as brilliant/stupid/evil/pedantic/insipid/inspired as the post you just read? Check out the Hraka Essentials, the (mostly) reader-selected guide to Hraka's best posts, and decide for yourself.
Comments

But that's the prob with relying on IP addresses...63.247.131.116 really meant hermes.hmdnsgroup.com, not silflayhraka.com. With ARIN's new restrictions dedicated IP addresses are not as easy to come by these days...we require hoop jumping and actual blood donation first.*

*No, not really.

Posted by: Stacy at October 23, 2003 02:58 PM
Post a comment Note: Comments with more than two dashes per line will be blocked as spam.









Remember personal info?