Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6241753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:49:32+00:00 2026-05-24T11:49:32+00:00

Im writting up an automated backup and mirroring script which will more or less,

  • 0

Im writting up an automated backup and mirroring script which will more or less, copy over the files, the db, setup permissions, and modify the mirrored files slightly so they work on the other server with the backed up file. I’ve written and set everything else up except the reconfig. All my attempts have failed and I don’t know how to get around it.

So these are the relevent lines(modified for public use):

FOLDER="kf.hammertime.com.au"
SERVER="fulcan"
BACKUPUSER="backupclient3"
DESTINATION="/var/www/Backup-Server"
SOURCE="/var/www"

RECONFIG="1"

if [ "${RECONFIG}" = "1" ]
then
#Original to be replace
echo Reconfiguring website for the mirrored site.
REPLACESTRING10="define (\'ROOT_PATH\', \'\/var\/www\/${FOLDER}\/trunk\')"
REPLACESTRING20="define ('DB_PASSWORD', 'hammertime1')"
REPLACESTRING30="define ('DB_USERNAME', 'hammertime2')"
REPLACESTRING40="define ('DB_HOST', 'localhost')"

#String to be replaced
REPLACESTRING11="define ('ROOT_PATH', '${SOURCE}\/${FOLDER}')"
REPLACESTRING21="define ('DB_PASSWORD', 'hammertime3')"
REPLACESTRING31="define ('DB_USERNAME', 'hammertime4')"
REPLACESTRING41="define ('DB_HOST', 'hammertime5')"

REPLACESTRING12="define (\'ROOT_PATH\', \'${SOURCE}\/${FOLDER}\/trunk\')"

echo ${REPLACESTRING10}

#Reconfigure various configuration files for Backup-Server active use

#find /your/home/dir -name "*.txt" | xargs perl -pi -e 's/stringtoreplace/replacementstring/g'

#Edits the files regardless if its in trunk or not. Will come up with errors.

#sudo replace "${REPLACESTRING10}" "${REPLACESTRING12}" <${DESTINATION}/${FOLDER}/trunk/lib/config.php> ${DESTINATION}/${FOLDER}/trunk/lib/config2.php

#sudo sed -i s/"${REPLACESTRING10}"/"${REPLACESTRING12}"/g  ${DESTINATION}/${FOLDER}/trunk/lib/config.php

#sudo perl -i -p -e 's{${REPLACESTRING10}}{${REPLACESTRING12}}g' ${DESTINATION}/${FOLDER}/trunk/lib/config.php


sudo sed -i 's/${REPLACESTRING10}/${REPLACESTRING12}/g' ${DESTINATION}/${FOLDER}/trunk/lib/config.php

#sudo sed -i 's/${REPLACESTRING10}/${REPLACESTRING11}/g' ${DESTINATION}/${FOLDER}/lib/config.php

#sudo sed -i 's/${REPLACESTRING20}/${REPLACESTRING21}/g' ${DESTINATION}/${FOLDER}/trunk/lib/config.php
#sudo sed -i 's/${REPLACESTRING20}/${REPLACESTRING21}/g' ${DESTINATION}/${FOLDER}/lib/config.php

#sudo sed -i 's/${REPLACESTRING30}/${REPLACESTRING31}/g' ${DESTINATION}/${FOLDER}/trunk/lib/config.php
#sudo sed -i 's/${REPLACESTRING30}/${REPLACESTRING31}/g' ${DESTINATION}/${FOLDER}/lib/config.php

#sudo sed -i 's/${REPLACESTRING40}/${REPLACESTRING41}/g' ${DESTINATION}/${FOLDER}/trunk/lib/config.php
#sudo sed -i 's/${REPLACESTRING40}/${REPLACESTRING41}/g' ${DESTINATION}/${FOLDER}/lib/config.php
fi

So in short the line “sudo sed -i ‘s/${REPLACESTRING10}/${REPLACESTRING12}/g’ ${DESTINATION}/${FOLDER}/trunk/lib/config.php” doesn’t take in variables very well at all.

So ive tried using the perl alternative but to no avail (but i could have been n00bing it). Most of my attempts are listed there. As well as replace.

I just need to change certain lines (the line numbering can change) in a single file.

Thanks in advance for your time and Patience (By the way, this is the first time writing an SH script, I’m used to BAT, so I’m sure I’ve n00bed a fair chunk of it, but it works well with no errors)

EDIT:
The file chunk looks like:

define ('ROOT_PATH', '/var/www/kf.hammertime.com.au/trunk');
define ('DB_HOST', 'hammertime1');
define ('DB_USERNAME', 'hammertime2');
define ('DB_PASSWORD', 'localhost');

And i want to change it to:

define ('ROOT_PATH', '/var/www/Backup-Server/kf.hammertime.com.au/trunk');
define ('DB_HOST', 'hammertime3');
define ('DB_USERNAME', 'hammertime4');
define ('DB_PASSWORD', 'hammertime5');

But some of these edited items will be variables…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:49:33+00:00Added an answer on May 24, 2026 at 11:49 am

    Variable replacement inside of sed strings must be in double quotes. i.e., you have

     sudo sed -i 's/${REPLACESTRING10}/${REPLACESTRING12}/g' ${DESTINATION}/${FOLDER}/trunk/lib/config.php
    

    replace with

     sudo sed -i "s/${REPLACESTRING10}/${REPLACESTRING12}/g" ${DESTINATION}/${FOLDER}/trunk/lib/config.php
    

    Fix this and then tell us what the next problem is. You may need to escape any space or tab chars embedded in the REPLACESTRINGn like

    REPLACESTRING20="define\ ('DB_PASSWORD',\ 'hammertime1')"
    # ---------------------^  --------------^
    

    Edit

    And of course, the killer of all sed issues, is the embedded ‘/’ in the either the search string or the replacment string. Most seds allow using other characters besides the ‘/’, so try

     sudo sed -i "s#${REPLACESTRING10}#${REPLACESTRING12}#g" ${DESTINATION}/${FOLDER}/trunk/lib/config.php
    

    Some seds ‘insist’ that you escape the first char if it is not ‘/’, so if just plain s#...#...#g' doesn't work, trys\#…#…` (just the first mention of #). AND if you have ‘#’ chars in either your target or repl string, then you’ll have to find a different delimiter to use.

    It will help if you use the shell debugging mode, i.e. set -vx (insert near top of script). Then you’ll see each line as it is executed with the variables expanded to their assigned values.

    I hope this helps.

    P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a shell script which iterates over a set of variables, edits a
I am writing a script that will do some automated things, and it requires
Background: writing an automated release script to export changed files between versions from SVN
I am writing a bash script to deal with some installations in an automated
I'm writting a financial C# application which receive messages from the network, translate them
I am writing an automated test script in python and I need to integrate
I am writing a Perl script that needs to transfer files between computers using
I'm writing an automated test to determine whether or not rtf files are successfully
I'm writing a VMWare ESX automated build script and I'm falling at the last
I'm writing a semi-automated deploy script that allows users to tag the repository at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.