LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-09-2011, 12:47 PM   #1
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 294

Rep: Reputation: 10
PIPE Symbol not recognized in Script


Hi this is the simple backup script which i used to take backup the databases of my clients

Code:
#!/bin/bash
date=`date +%d-%m-%Y_%H.%M.%S`
echo Backup Started $date  >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log
###########################################################
#create directory to store mysql database backup
mkdir /var/tmp/anishdatabasesbackup$date
if [ $? -ne 0 ]
then echo "Backup failed with errors" for $date >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log
exit
else
echo “directory mysqldatabasebackup$date created”  >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log
fi
# Back up anish.com Databases
###########################################################
db = $MYSQL > /var/tmp/db
for db in $(mysql -u admin -pPASSWORD -D psa -e "select name from data_bases where dom_id=(SELECT id FROM domains where name='anish.info');" | sed '1d' > /var/tmp/db)
do
       mysqldump -u admin -pPASSWORD  $db >> /var/tmp/anishdatabasesbackup$date/$db.sql
       echo DUMPING DATABASE ""$db"" >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log
       echo backup copy of $db is moved to /var/tmp/anishdatabasesbackup$date >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log
        cd  /var/tmp/anishdatabasesbackup$date
        a=`du -sh $db.sql | cut -f1`
        echo THE SIZE OF $db.sql FILE IS $a >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log
done
echo "Backup completed successfully $date" >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log

cat /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log | mail -s "anishdatabasesbackup" 07anis@gmail.com

Now my requirement is from mysqldb i need to get some values from that 2 values(databases) that only i need to dump.

From Db to get the values i use this command in script.

Code:
mysql -u admin -pPASSWORD -D psa -e "select name from data_bases where dom_id=(SELECT id FROM domains where name='anish.info');"
Output of this command is like this but i need only values db_trace and db_morrilton

Quote:
+-----------------+
| name |
+-----------------+
| db_trace |
| db_morrilton |
+-----------------+

so i add sed in this mysql command to delete the first line alone,


Code:
mysql -u admin -pPASSWORD -D psa -e "select name from data_bases where dom_id=(SELECT id FROM domains where name='anish.info');" | sed '1d' > /var/tmp/db
It give the exact output what i expect but in script the pipe symbol | not recognized so the script is not working, Don't know what mistake exactly i am doing, kindly look this script and guide me to solve this thread.
 
Old 08-09-2011, 01:13 PM   #2
shamgar03
Member
 
Registered: Jul 2004
Distribution: Gentoo, CentOS
Posts: 92

Rep: Reputation: 15
stdout

Is the output of the mysql query going to stdout or stderr? If it only goes to stdout, all that is being redirected to /var/tmp/db isn't it? Maybe remove the redirect "> /var/tmp/db"
 
Old 08-09-2011, 01:25 PM   #3
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 294

Original Poster
Rep: Reputation: 10
Hi dude,

I need to store that values in file only, from that file only i need to get the values man and that value only i need to dump.
 
Old 08-09-2011, 01:44 PM   #4
shamgar03
Member
 
Registered: Jul 2004
Distribution: Gentoo, CentOS
Posts: 92

Rep: Reputation: 15
But you make no further references to /var/tmp/db or $MYSQL and each pass through the loop will overwrite /var/tmp/db. The for loop is already going to capture the output from the mysql query, there is no need to write it to a file.
 
Old 08-09-2011, 01:57 PM   #5
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 294

Original Poster
Rep: Reputation: 10
Hi man,

If i did that like means the scrip considered

Quote:
+-----------------+
| name |
+-----------------+

This also a DB man.
 
Old 08-09-2011, 02:00 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by anishkumarv View Post
Hi this is the simple backup script which i used to take backup the databases of my clients

Code:
#!/bin/bash
date=`date +%d-%m-%Y_%H.%M.%S`
echo Backup Started $date  >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log
###########################################################
#create directory to store mysql database backup
mkdir /var/tmp/anishdatabasesbackup$date
if [ $? -ne 0 ]
then echo "Backup failed with errors" for $date >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log
exit
else
echo “directory mysqldatabasebackup$date created”  >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log
fi
# Back up anish.com Databases
###########################################################
db = $MYSQL > /var/tmp/db
for db in $(mysql -u admin -pPASSWORD -D psa -e "select name from data_bases where dom_id=(SELECT id FROM domains where name='anish.info');" | sed '1d' > /var/tmp/db)
do
       mysqldump -u admin -pPASSWORD  $db >> /var/tmp/anishdatabasesbackup$date/$db.sql
       echo DUMPING DATABASE ""$db"" >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log
       echo backup copy of $db is moved to /var/tmp/anishdatabasesbackup$date >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log
        cd  /var/tmp/anishdatabasesbackup$date
        a=`du -sh $db.sql | cut -f1`
        echo THE SIZE OF $db.sql FILE IS $a >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log
done
echo "Backup completed successfully $date" >> /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log

cat /var/tmp/anishdatabackuplog/anishdatabasesbackup$date.log | mail -s "anishdatabasesbackup" 07anis@gmail.com

Now my requirement is from mysqldb i need to get some values from that 2 values(databases) that only i need to dump.

From Db to get the values i use this command in script.

Code:
mysql -u admin -pPASSWORD -D psa -e "select name from data_bases where dom_id=(SELECT id FROM domains where name='anish.info');"
Output of this command is like this but i need only values db_trace and db_morrilton




so i add sed in this mysql command to delete the first line alone,


Code:
mysql -u admin -pPASSWORD -D psa -e "select name from data_bases where dom_id=(SELECT id FROM domains where name='anish.info');" | sed '1d' > /var/tmp/db
It give the exact output what i expect but in script the pipe symbol | not recognized so the script is not working, Don't know what mistake exactly i am doing, kindly look this script and guide me to solve this thread.

Why use sed in a roundabout way if you can simply use
-s -r switches to MySQL to suppress lines and headers?




Cheers,
Tink
 
Old 08-09-2011, 02:24 PM   #7
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 294

Original Poster
Rep: Reputation: 10
Hi all,

Thanks a lot Guys Atlast I found the Easiest way

instead of -e i use -Bse That skips the Table header. and its working fine.

mysql -u admin -pPASSWORD -D psa -Bse "select name from data_bases where dom_id=(SELECT id FROM domains where name='anish.info');"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a "Pipe" symbol? markw8500 Linux - Newbie 28 02-02-2020 09:56 AM
Pipe symbol James Maki LinuxQuestions.org Member Success Stories 0 11-17-2010 12:31 PM
How do I get the pipe symbol on a uk keyboard? markhod Linux - General 4 11-03-2004 02:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration