Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Am I missing something, or is removing the commas the only thing you really need to do?
Code:
sed 's/,//g' file
Unfortunately, you put your example text inside of quote tags instead of the [code][/code] tags that you should've used, so any formatting you may have had was lost. If the entries are actually supposed to be separated by tabs, for example, then you can use the same command to replace the comma+space combination with a tab character instead.
in this line first column contains client name and 2,3,4,5,6 column contains client databases names.
and my requirement is every time the script runs it creates on directory in the client name(column1) and start dumping the databases(column 2,3,4,5,6) using mysql dump, and move those dump databaes into (column1) directory.
like this we have to do for our every clients. is it possible to do ? guide me guys to solve this thread.
Last edited by anishkumarv; 08-12-2011 at 07:30 AM.
So how about we start at the beginning and you tell us exactly what is required instead of spoon feeding us bits and pieces?
My first question to you would be, what is the manual process you currently use to do whatever it is you are trying to accomplish?
(ie if you type one command at a time on the command line how can you accomplish your task)
I can see that English isn't your first language. There's nothing you can do about it, as long as you are trying your best. I does make it hard for me to understand what you want exactly.
I understand that you want to execute some external programs. You can do that inside awk:
This will create a directory with the name based on the first field in the file. Then it will write a mysqldump of all the databases named on the rest of the line to a file in that directory.
You can adapt my example for the purpose you really need.
Thanks Man, Even Iam also not like Spoon feeding, and my exact requirement is am writing a script to take mysql backups in shared hosting, using plesk control panel we configured shared hosting in our server,
Code:
#!/bin/bash
date=`date +%Y-%m-%d_%H.%M.%S`
echo Backup Started $date >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
###########################################################
#create directory to store mysql database backup
mkdir /var/tmp/mysqldatabasebackup$date
if [ $? -ne 0 ]
then echo "Backup failed with errors" for $date >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
exit
else
echo “directory mysqldatabasebackup$date created” >> /var/tmp/mysqlbackuplog/mmysqldatabasebackup$date.log
fi
# Back up MySQL databases
###########################################################
# Do not backup these databases
IGNORE="information_schema mysql test argali mechcicadd_rlite information_schema"
# Get list of all databases
DB_LIST=`mysql -pPASSWORD -Bse 'show databases'`
if [ $? -ne 0 ]
then
echo backup failed with errors >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
exit
fi
for db in $DB_LIST; do
# set skip variable
skip=0
if [ "$IGNORE" != "" ]; then
for i in $IGNORE; do
[ "$db" == "$i" ] && skip=1 || :
done
fi
if [ "$skip" == "0" ]; then
mysqldump $db >> /var/tmp/mysqldatabasebackup$date/$db.sql
echo DUMPING DATABASE FOR CLIENT ""$db"" >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
echo backup copy of $db is moved to /var/tmp/mysqldatabasebackup$date >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
cd /var/tmp/mysqldatabasebackup$date
a=`du -sh $db.sql | cut -f1`
echo THE SIZE OF $db.sql FILE IS $a >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
fi
done
echo "Backup completed successfully $date" >> /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log
cat /var/tmp/mysqlbackuplog/mysqldatabasebackup$date.log | mail -s "mysqlbackuplog" dineshkumar.baskar@cevalsoft.com,anish.valsalam@cevalsoft.com
Using this script i can able to take all the databases backup,
but my requirement is need to take all the databases backup with owner details ( owner details in the sense need to create directory in the name of client name.) so first i follow these steps to customize the above script.
1. need to get the client name and databases name.
so using the mysql query i get the client name and along with the corresponding databases.
if i execute a mysql query means i got this output.
No problems on not having great English as those that supposedly can speak it are often not very eloquent anyway
I think I am following better now, but just want to know at what point in the script you have shown would you now run the mysql query to retrieve the
data in the format you mention?
I only ask as the script appears to already be making backups. Is this new requirement to happen after all of what we currently see?
ya dude this is my new requirement, i need to add this in script. but still i didn't get any idea for this requirement struggling,
Code:
mysql -u admin -pPASSWD -D psa -Bse "select a.name, group_concat(b.name separator ', ') from domains a, data_bases b where a.id=b.dom_id group by a.name;"
Using this command i am getting the client name and client databases alone.
Well I would say the easiest thing to do would be simply change the separator to a space (not sure if that is the default as not familiar with mysql).
So I would probably do some thing like:
Code:
while read -r client dbs
do
dir=/path/to/clients/$client
mkdir "$dir"
mysqldump --databases "$dbs" "$dir/"
done< <(mysql -u admin -pPASSWD -D psa -Bse "select a.name, group_concat(b.name separator ' ') from domains a, data_bases b where a.id=b.dom_id group by a.name;")
Again I do not know how mysqldump works (ie if it generates the names for each database) so if it doesn't create the names you could easily implement a for loop to do each one.
Thanks For the Reply. Sorry for the late reply we are in celebration mood (Independence day here :-)) but still My Script Problem is continuing :-( :-(
Code:
bbkup.sh: line 9: syntax error near unexpected token `<'
dbbkup.sh: line 9: `done < <(mysql -u admin -pPASSWD -D psa -Bse "select a.name, group_concat(b.name separator ' ') from domains a, data_bases b where a.id=b.dom_id group by a.name;");'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.