Good evening,
I'm trying to grep a list of databases stored within a MYSQL dump but I'd like to adjust some of the settings - I'm unsure how to do so.
The code is currently;
#!/bin/sh
echo "What is the cPanel username!"
read cpuser
cd /home/${cpuser}/public_html
sqldump=$(find . -name \*.sql -type f)
sqlversion=$(grep "Server version" ${sqldump})
sqldbs=$(grep "CREATE DATABASE" ${sqldump})
echo "The dump location is"
echo $sqldump
echo "The SQL version is"
echo $sqlversion
echo "The databases in the dump are"
echo $sqldbs
The output of that is ( in this example )
What is the cPanel username!
domain1mysql4
The dump location is
./test/xxx/database/xxxx.sql
The SQL version is
-- Server version 4.1.14
The databases in the dump are
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `blog` /*!40100 DEFAULT CHARACTER SET latin1 */; CREATE DATABASE /*!32312 IF NOT EXISTS*/ `blog1` /*!40100 DEFAULT CHARACTER SET latin1 */; CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mysql` /*!40100 DEFAULT CHARACTER SET latin1 */;
I have two questions, ultimately.
Is it possible to only list the databases that it outputs 'blog' 'blog1' 'mysql' rather than the rest of the line?
Is it also possible to then save those as a variable to be called later in the script?
Output after freddy adjustment
sh ./test.sh
enter the cPanel username: domain10mysql4
./home/saiprem/xxxxx/database/xxxx.sql:activesearch
./home/saiprem/xxxxx/database/x.sqxxxxl:alienstats
./home/saiprem/x/database/xxxxxx.sql:anahaw
xxxx./home/saiprem/x/databasxxxe/xxxx.sql:b2
./home/saiprem/x/database/x.sql:beeforumxxx