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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to read matched parameters from textfile

Status
Not open for further replies.

monuntainyman

Programmer
Jan 17, 2011
5
0
0
IE
Hi all,

The script below is intended to help in exporting a wordpress website from a staging server to a domain.

It accepts 2 inputs an old domain and a new domain. These are put in manually at the start of the export process.

I would like to read in a list of old domains and new domains in the following format

Code:
fish.staging.ie:ilovefish.ie
cows.staging.ie:thecowssite.com
love.staging.ie:whatislove.net

and have the process run automatically.

This is the process as it stands I prompt myself for both values.
Code:
#!/bin/bash
#Script to alter text in database in order to prepare a 
#wordpress website for export
read -p "Enter the old  domain name :   " OLD_DOMAIN
read -p "Enter the new domain name :   " NEW_DOMAIN

PATH_TO="/supermonkey/newsites/"

/usr/bin/mysqldump  -f -u dbuser-sme"$OLD_DOMAIN"  -p[PASSWORD] sme"$OLD_DOMAIN" >""$PATH_TO"/"$NEW_DOMAIN"/sme"$NEW_DOMAIN".SQL"
SQL_FILE=""$PATH_TO"/"$NEW_DOMAIN"/sme"$NEW_DOMAIN".SQL"


    if [ -f $SQL_FILE ]
        then 
            read -p "Step 01 Complete: SQL File created"
        else 
            read -p "Step 02 Failed: SQL File was not created"
    fi

I tried this before and it worked but only if the file only contained 1 pair of values. Otherwise the sed happened at what looked like random.
Code:
#!/bin/bash

#Script to read a list of files and convert databases
while IFS=: read OLD_DOMAIN NEW_DOMAIN
do  


done < /home/supermonkey/allsites/supmdomainlist.txt
 
Thanks for letting me know that!

I was stripping out the irrelevant code and accidentally stripped out the very relevant as well.

The sed is at the end of the block below.

Code:
read -p "Enter the old  domain name :   " OLD_DOMAIN
read -p "Enter the new domain name :   " NEW_DOMAIN

PATH_TO="/mountainyman/newsites/"

/usr/bin/mysqldump  -f -u dbuser-sme"$OLD_DOMAIN"  -p[PASSWORD] sme"$OLD_DOMAIN" >""$PATH_TO"/"$NEW_DOMAIN"/sme"$NEW_DOMAIN".SQL"
SQL_FILE=""$PATH_TO"/"$NEW_DOMAIN"/sme"$NEW_DOMAIN".SQL"


    if [ -f $SQL_FILE ]
        then
            read -p "Step 01 Complete: SQL File created"
        else
            read -p "Step 02 Failed: SQL File was not created"
    fi


sed "s|$OLD_DOMAIN|$NEW_DOMAIN|g" "$PATH_TO"/"$OLD_DOMAIN"/"$OLD_DOMAIN".SQL> "$PATH_TO"/"$OLD_DOMAIN"/"$NEW_DOMAIN""01"".SQL"

 
read -p "Step 01 Complete: SQL File created" [!]</dev/tty[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi

Please stop using that ugly and completely useless quoting style.

One problem could be with the dots ( . ) in the old domain. Dot is metacharacter in regular expression, meaning any character. You should escape them by prefixing them with backslash ( \ ) :
Code:
sed "s|${OLD_DOMAIN//./\.}|$NEW_DOMAIN|g" "$PATH_TO/$OLD_DOMAIN/$OLD_DOMAIN.SQL" > "$PATH_TO/$OLD_DOMAIN/${NEW_DOMAIN}01.SQL"
monuntainyman said:
Otherwise the sed happened at what looked like random.
Could you show us such wrong output of [tt]sed[/tt] ?


Feherke.
 
My apologies re the quoting style. I will endeavor to improve the style of my scripts.
Before I post the mismatched output I will try to run the script again escaping the dots and specifying teletype to read in the list of parameters.
 
hi PHV,

Is the reason that I need to specify the ttv that I am filling the buffer available for each terminal instance? If so I am out of my depth and would be better to stick to my current working process right now.

Thanks
 
Code:
while IFS=: read OLD_DOMAIN NEW_DOMAIN
do  
# all read commands inside the loop should have a redirected standard input
done < /home/supermonkey/allsites/supmdomainlist.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top