LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-23-2005, 04:54 PM   #1
rharris72
Member
 
Registered: Nov 2005
Posts: 32

Rep: Reputation: 15
mysql and bash


is there away of getting some info from a database and then getting a bash script to asign it to a string so i can use it to sed into an existing file

thanks in advance
 
Old 12-24-2005, 06:01 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Sure.
Example:
Code:
#!/bin/bash

USER=root
PASSWD=secret

printcolumns()
{
    TABLE=$1
    echo "describe $TABLE" \
      | mysql -s -B -u $USER --password=$PASSWD mysql \
      | while read COL; do
        COLNAME=$(echo $COL | cut -f1)
        echo -e "\t$COLNAME"
    done
}

echo "show tables" \
  | mysql -s -B -u $USER --password=$PASSWD mysql \
  | while read TABLE; do
    echo 'Table: "'${TABLE}'" :'
    printcolumns $TABLE
    echo
done

Last edited by Hko; 12-24-2005 at 06:02 AM.
 
  


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
Bash scripting, mysql, and creating tables. hondaman Linux - General 2 09-25-2005 05:17 AM
Bash + Mysql Help xianzai Programming 4 10-28-2004 08:15 AM
Mysql in bash script acrors Red Hat 2 08-18-2004 09:11 PM
Bash script and mysql flashingcurser Programming 1 07-19-2004 03:35 AM
Bash and mysql connections. tia24 Linux - Newbie 1 04-13-2004 01:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:08 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