newwpuser=$cpuser"_"$wpuser
newwpdb=$cpuser"_"$wpdb
wpdb=($(find . -name "wp-config.php" -print0 | xargs -0 -r grep -e "DB_NAME" | cut -d \' -f 4))
wpuser=($(find . -name "wp-config.php" -print0 | xargs -0 -r grep -e "DB_USER" | cut -d \' -f 4))
wpconfigchanges=($(find . -name wp-config.php -type f))
for i in "${wpconfigchanges[@]}"; do -exec sed -i -e "/DB_USER/s/'$wpuser'/'$newwpuser'/" | -exec sed -i -e "/DB_NAME/s/'$wpdb'/'$newwpuser'/"; done
I am trying to run the above in order to find all wordpress configs and append the db user and dbname with cpuser_
However - I get the following error;
./test.sh: line 85: -exec: command not found
./test.sh: line 85: -exec: command not found
Have I inputted the exec commands wrong?
CPUser is inputted on execution
CodePudding user response:
Yes, you have inputted the exec commands wrongly. The -exec
option should be written in a separate line. Also, you need to add ;
at the end of each -exec
command to indicate the end of the command.
Here's a corrected version of your script:
newwpuser=$cpuser"_"$wpuser
newwpdb=$cpuser"_"$wpdb
wpdb=($(find . -name "wp-config.php" -print0 | xargs -0 -r grep -e "DB_NAME" | cut -d \' -f 4))
wpuser=($(find . -name "wp-config.php" -print0 | xargs -0 -r grep -e "DB_USER" | cut -d \' -f 4))
wpconfigchanges=($(find . -name wp-config.php -type f))
for i in "${wpconfigchanges[@]}"; do
sed -i -e "/DB_USER/s/'$wpuser'/'$newwpuser'/" $i
sed -i -e "/DB_NAME/s/'$wpdb'/'$newwpuser'/" $i
done