Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-08-17
2
Medium Priority
?
397 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 2000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Utilizing an array to gracefully append to a list of EmailAddresses
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

664 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