Solved

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

Posted on 2010-09-24
10
494 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
10 Comments
 
LVL 14

Assisted Solution

by:Kalpan
Kalpan earned 249 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 50

Accepted Solution

by:
Steve Bink earned 250 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 50

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 68

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Learn about cloud computing and its benefits for small business owners.
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:…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

911 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

19 Experts available now in Live!

Get 1:1 Help Now