Scott Haneda wrote:

My query works:
(version 4)

SELECT u.id, r.user_id,
u.first_name, u.middle_name, u.last_name,
u.company, u.department, u.address, u.address2,
u.city, u.state, u.country, u.zip,
u.phone, u.fax, u.email,
DATE_FORMAT(u.updated, '%m/%d/%Y'), DATE_FORMAT(u.added, '%m/%d/%Y'),
r.serial, r.product, DATE_FORMAT(r.added, '%m/%d/%Y')
FROM user as u INNER JOIN registered_serials as r
WHERE u.id = r.user_id LIMIT 10


However, I need to run this once a day on schedule via cron, but I am not
sure how to feed this statement into mysql from bash, can someone point me
to the correct way?


Write your script with the following line at the top:

tee /path/to/output/file.sql

The 'tee' command tells mysql to output to the given file. The put the select / whatever commands after this command. Save the file, for example, as my_nightly_sql_commands.sql The set up a cron job to call the script:

#!/bin/sh
mysql -u username -ppassword < /path/to/my_nightly_sql_commands.sql

Note that there is NO space between the '-p' and the password.

That's about it. I haven't tested the above, but it should work. At least I use each of the individual parts at one point or another, but never all together.

Dan

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to