Names changed to protect the innocent.

Say you want to duplicate some web pages to another server, but the web server names are different. That means all the links in the pages will be wrong. For example take the following simple web page:

[code]
<html>
<title> Offshore Educators (C1001) </title>
 <title> Send us some comments </title>
 <body bgcolor="aquamarine">
    <CENTER><h2><B><I>Offshore Educators</I></B></h2></CENTER>
Sylabus: C1001 - Introduction to computing 1.
<hr>
<br>
<p>
This course introduces students to fundamental hardware concepts in the use of microcomputers and to some practical applications of software. The course focuses primarily on word processing, spreadsheets and business charts and presentation software using the Open Office products on the Linux platform. The course examines the use of computers for communication and collaboration including e-mail, conferencing software and the Internet for exploring the resources of the World Wide Web. Students participate in group discussions using groupware, work with computerized library databases and make decisions about the purchase of hardware, software and service providers.
</p>

<a href="descripts.html"> Returm me to the class listing</a>
<br>
<a href="http://oesrvr1"> Click on me to return to the homepage!</a>
[/code]

Our goal is to change oesrvr1 to oemsrvr1. Now just for one file this is no big deal, unless you have tens or even hundreds of web pages. Then you are talking about a major project to change all the server names in links. This can be made real easy.  After the web pages have been copied over, just go to the appropriate web directory such as /var/www on the new server and issue the following command:

$ sudo grep -lr -e 'oesrvr1' * | xargs sudo sed -i 's/oesrvr1/oemsrvr01/g'

In a few seconds all the files are changed without having to edit a single file.  So now
"<a href="http://oesrvr1"> Click on me to return to the homepage!</a>" is changed to
"<a href="http://oemsrvr01"> Click on me to return to the homepage!</a>".

This command is for a nix based system, but you could share an MSWindows server web directory and let a nix box access the web directories via samba to make the needed changes. (Do it while the server is offline for security purposes.)


Go one step further to automate it using namechange.sh.

namechange.sh
[code]
 sudo grep -lr -e '$1' * | xargs sudo sed -i 's/$1/$2/g'
[/code]

Then at the command line you could use:
$ namechange.sh oesrvr1 oemsrvr01

More than one way to skin a cat. Hope this artcle helps you out. Definitely helped me out.

Comments

Popular posts from this blog

Guiless?

Web.com and Network Solutions, the Walmart of the internet.

MSOffice vs Libreoffice