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!"
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!"