Solved

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

Posted on 2010-09-24
10
492 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
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…

747 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

14 Experts available now in Live!

Get 1:1 Help Now