Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Read & Write into .ini file, using MySQL + Cron.

Posted on 2010-09-24
10
Medium Priority
?
530 Views
Last Modified: 2012-05-10
I have .ini file in server. I want to update that file automatically with data which is in MySQL database.

How or what kind of ways are there to do it? Currently Im thinking about using MySQL and Cron but I have no idea about where to start.
0
Comment
Question by:LifeWay5
7 Comments
 
LVL 14

Assisted Solution

by:Kalpan
Kalpan earned 996 total points
ID: 33752926
From the cPanel, go to Cron jobs, select Standard, and enter (between the quotes)
"/usr/bin/php -q /home/USERNAME/public_html/PathToFile" into the Command to run field.
You may also want to adjust the settings specifying when to run the cron job. After you finished, click on the SaveCrontab button.

You will need to replace USERNAME with your user ID and PathToFile with the file name or the rest of the path to the file.

If you want to use your own php.ini settings for the script you are running you will need to add the following "-c /home/USERNAME/PathTo/php.ini" to the cron job entry.
0
 

Author Comment

by:LifeWay5
ID: 33755152
Sorry, I think you misuderstood me.

I want to write data which is in MySQL at host yy.yy.yy.yy into public_html/whateverfilename.ini which is at host xx.xx.xx.xx
0
 

Author Comment

by:LifeWay5
ID: 33773970
help`?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Accepted Solution

by:
Steve Bink earned 1000 total points
ID: 33847340
kalmax had the correct answer, but he left a bit of it out.

The first step is to create the program or script which will change the ini file.  This can be done with bash scripting, PHP, or even a compiled application you make especially for the job.  The app should connect to your database, query the necessary data, and either rewrite the ini from the ground up or find/replace existing configuration items in it.  In PHP, this would be done with the mysql/i libraries, as well as fopen() and fwrite().  The goal here is to write an application that queries a database and writes a text file.

The second step is essentially what kalmax posted: use cron to schedule this application to run.  His example assumed PHP, which admittedly is an extremely simple option to implement, but how cron launches your app will depend on what you used to code it originally.  The important note here is that the app must run as a user account capable of editing the ini file.  The easiest solution is root, though that is not necessarily the best solution.  You also have to consider the services that actually use the ini file.  If the service is running, you may need to shut it down to modify the file, or restart it after the modification to read the current config.
0
 

Author Comment

by:LifeWay5
ID: 33924340
thats more getting there but Im not really a coder, would need help to code something which could change ini file.
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 33927815
You're going to need to learn some PHP or bash scripting to get this done.  I recommend starting with PHP just because the syntax is easier and the documentation is well-organized: http://www.php.net.  Break the job up into pieces:

1) Make a PHP script that connects to the database and returns data.  
2) Make a PHP script that reads an INI file, and writes an INI file.
3) Make a PHP script that changes bits of text within a large area of text.

When you have those three things, put them all together and you have your application.  Start out with #1 and see where it leads you.  Come back if you run into difficulties, and I'll help you through the specifics.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 34367494
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this article, we’ll look at how to deploy ProxySQL.
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

824 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