Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Utilizing an array to gracefully append to a list of EmailAddresses
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

707 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

18 Experts available now in Live!

Get 1:1 Help Now