Solved

Freebsd 8, script to extract from mysql and write to file

Posted on 2010-08-17
2
395 Views
Last Modified: 2013-12-21
I have a freebsd machine v8 which has mysql on it with a database called "slave_data" and a table called "valid_local_users" with a column called "email_address".

what I want to do is run a script every 5 mins to extract "email_address" and write each record to a file.

"/usr/shared/valid_users/localusers.txt"

file needs to looks like.

john@doe.co.uk
jane@doee.com
simon@simons.co.uk

I know that i need to create a script and then use the crontab to schedule however i dont really know much about the script i need to write.

Could I please have some example or pointers.

I have googled but I dont fully understand all the points.
0
Comment
Question by:purpleoak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
stermeau earned 500 total points
ID: 33453100
Is there a timestamp in your "valid_local_users" table?
If not, then you will have to download all the emails every 5 min.

The script should be like this

#!/bin/sh
mysql -h <server_ip> -u <user> -p<pwd> slave_data -e "select distinct email_address INTO OUTFILE '/tmp/result.txt' LINES TERMINATED BY '\n' FROM valid_local_users;"

and your crontab should be :
*/5 * * * * /bin/sh <path_to_the_script>

0
 
LVL 2

Author Closing Comment

by:purpleoak
ID: 33466603
This was exactly what I needed. I didn't know the mysql query part.

Thank you very much for all your help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question