Welcome to WebmasterWorld Guest from 54.145.4.19

Forum Moderators: bakedjake

Message Too Old, No Replies

Bash Redirect Database Connection Info

update script for database connection info

     

CafeSelect

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

10+ Year Member



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

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

10+ Year Member



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month