Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OK - Time to call in the help?

Status
Not open for further replies.

BobMCT

IS-IT--Management
Sep 11, 2000
756
US
Guru's:

I am in the process of migrating some web sites from one server to another. Some of the original site code is quite old and not very standards compliant.

Some of the html files contain php instructions and the web server on the new server is NOT recognizing it most likely because its only parsing php extension files.

Therefore I have created a shell script to search for html files with embedded <? characters and then rename them to php files AND both write a substitution to a sed file AND write a redirect entry to a file to be added to the httpd.conf file.

I am running into a problem where this script is ALWAYS failing claiming an unmatched " character (which as far as I could tell is NOT unmatched).

If anyone is inclined, please take a look at the following script and advise where my blatant error(s) might be?

Thanks,

#!/bin/bash
##########################################################
# [html2php.sh] - used to change names of selected files
# and generate files of Apache redirects
# and file of sed substitutions
#
# Usage: ./html2php.sh
#
##########################################################
# Set SITENAME variable
SITENAME=$(cat $HOME/sitename)
if [[ ! $SITENAME ]]
then
echo "$HOME/sitename file was NOT found - Job cancelled!"
exit 3
fi
##########################################################
echo "html2php.sh is executing for ${SITENAME}..."
RLOG="$HOME/list-of.Redirects"
rm -f ${RLOG} tmp.*
##########################################################
# create list of html files that contain php statements
grep -rl "<\?" * >tmp.0
grep "\.html" tmp.0 >tmp.1
# Process ONLY if at least one file detected
if [[ -s tmp.1 ]]
then
echo "Generating Redirects for ${SITENAME}..."
echo "# Generated Redirects for ${SITENAME}" >${RLOG}
#####################################################
echo "Changing the following files names: "
for x in $(cat tmp.1)
do
set y=$(basename "$x")
read -p "file: $y"
echo "Changing: $y.html to $y.php"
mv $x.html $x.php
echo "^${x}\.html ${x}.php" >>${RLOG}
echo "s/$(y}\.html/${y}\.php/g" >>${SITENAME}.sed
done
########################################################
echo "File list-of.Redirects with $(cat $HOME/list-of.Redirects | wc -l) entries created!"
fi
##########################################################
unset RLOG
rm -f tmp.?
##########################################################
echo "html2php.sh has completed!"
 
Hi

Interesting misleading error message.
Code:
echo [green][i]"s/$[COLOR=red yellow]{[/color]y}[/i][/green][lime][i]\.[/i][/lime][green][i]html/${y}[/i][/green][lime][i]\.[/i][/lime][green][i]php/g"[/i][/green] [teal]>>[/teal][navy]${SITENAME}[/navy][teal].[/teal]sed

Feherke.
 
Hi

BobMCT said:
the new server is NOT recognizing it [gray](...)[/gray] embedded <? characters
I read all kind of rumors that [tt]short_open_tag[/tt] will be deprecated since PHP 6 and in certain circumstances it is set to off by default since PHP 5.3.3. If it is a new installation, I would check that before.

Feherke.
 
Thanks for the comments. I do not use short_open_tags myself but remember, this is a client's file(s). I supposed as I'm substituting anyway I should include the following sed line:

s/<\?\ /<\?php\ /g

 
You aren't going to believe this, but the typo you pointed out:
Interesting misleading error message.
CODE --> line 39
echo "s/${y}\.html/${y}\.php/g" >>${SITENAME}.sed

was NOT detect by myself or my other php peers. Wow, we must all be BLIND!

Thanks you -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top