homepage Welcome to WebmasterWorld Guest from 54.204.231.253
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Bash Redirect Database Connection Info
update script for database connection info
CafeSelect




msg:3599520
 1:56 pm on Mar 13, 2008 (gmt 0)

Can someone help me output to database.php the configuration values for that file including or not including the start and end php tags. There has to be a better way than this:

[j]<>/home/${USER}/database.php
#exec 3<> /home/${USER}/database.php
echo "<?php" 1> /home/${USER}/database.php
exec 3<> /home/${USER}/database.php
read -n 9 <&3
echo -n \'localhost\'; >&3
read -n 9 <&3
echo -n \'${USER}\'; >&3
read -n 9 <&3
echo -n \'$pass\'; >&3
read -n 9 <&3
echo -n \'${USER}\'; >&3
read -n 9 <&3
exec 3>&-
#echo "$dbuser=" 1>> "'${USER}';" 1>> /home/${USER}/database.php
#echo "$dbpass=" 1>> "'$pass';" 1>> /home/${USER}/database.php
#echo "$dbname=" 1>> "'${USER}';" 1>> /home/${USER}/database.php
#echo "$conn=" 1>> "mysql_connect($dbhost, $dbuser, $dbpass) or die ('Die');" 1>> /home/${USER}/database.php
#echo "mysql_select_db($dbname);" 1>> /home/${USER}/database.php
#echo "?>" 1>> /home/${USER}/database.php
#$dbhost='localhost:3306';
#$dbuser= 'user';
#$dbpass= 'pass';
#$dbname= 'tablespace';
#$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
#mysql_select_db($dbname);

What it needs to do is rewrite the database.php file everytime the script is ran.

 

CafeSelect




msg:3599623
 3:50 pm on Mar 13, 2008 (gmt 0)

ORIGINAL=uzer
REPLACEMENT=${USER}
ORIGINAL1=word
REPLACEMENT1=${pass}
ORIGINAL2=ts
REPLACEMENT2=${USER}

for word in $(fgrep -l $ORIGINAL /home/${USER}/database.php)
do
# -------------------------------------
ex $word <<EOF
:%s/$ORIGINAL/$REPLACEMENT/g
:%s/$ORIGINAL1/$REPLACEMENT1/g
:%s/$ORIGINAL2/$REPLACEMENT2/g
:wq
EOF
# :%s is the "ex" substitution command.
# :wq is write-and-quit.
# -------------------------------------
done

Solved

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved