Solved

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

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…

829 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