Solved

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

Posted on 2010-09-24
10
498 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
Are your AD admin tools letting you down?

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.

 
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 69

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

Suggested Solutions

Title # Comments Views Activity
SYbase 4 31
convert null in sql server 12 34
MySQL Backup Strategy 15 23
SQL Syntax: How to force case sensitive query? 2 29
Learn about cloud computing and its benefits for small business owners.
New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

773 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