Solved

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

Posted on 2010-09-24
10
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

 
LVL 51

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 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 70

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

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!

Question has a verified solution.

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

This article explains how to install and use the NTBackup utility that comes with Windows Server.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

630 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