Solved

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

Posted on 2010-08-17
2
388 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now