Please bear in mind I've got limited experience in this area and the timeout issue needs someone with better mySQL skills than me but
You probably need to think of this as two tasks. One a php script to transfer the data, the other a cron task to execute the php script.
The php script would have an INSERT command into the Oracle table using a select statement from the mySQL table. Thinking about it, it may be easier to run this from the Oracle server.
Setting up the cron task is a bit convoluted and differs between hosting interfaces I believe. Check out this quick reference guide - [adminschoice.com...]
I know it's not a full solution but hopefully it will get you underway.
There's more than one way of invoking the PHP parser so you'll likely need to experiment a bit to find the one that works for you.
Do you think this cron can be processed by a linux Op SYs?:
30 18 * * * php /path/to/php/file ? I know that if I replace php with rm for instance that's sure it'll be executed because rm is a linux command. What about this php?
Besides, on a linux system I have a file called crontab in /etc/crontab
Is it here where i have to write the previous command?
Thank you for your fast reply.
This is basic unix user level ...
Adding a line in the appropriate user's crontab is all what you need to do.
I'd replace "php" with the full path to the php command (type "which php" as command to find it) - assuming you have the command line php installed and in your PATH.
which php yields /usr/bin/php.
Thus, my php cron file begins so:
Notice the php script tag <?php at line 1 is omitted. Is this an error?
Besides, while creating the cron tab, the procedure i followed was this:
I logged in root, then typed 'crontab -e' where i typed the following as the crontab:
30 15 * * * /usr/bin/php /path/to/php/file > /tmp/export-to-oracle.log to be executed at the given time. I also did 'chmod' +x /path/to/php/file so that the file can be executed by the system.
Also notice that the ending php tag '?>' is omitted. So basically my whole php file looks like a text file.
To see whether the cron job was executed at all I open /var/log/cron and indeed i found something like:
Aug 8 16:42:01 barasukana-lp CROND: (root) CMD (/usr/bin/php /var/www/html/rcms/includes/exportMysqlToOracle.php > /tmp/export-to-oracle.log)
which show that the script was executed really. But, but, ...
when I open /tmp/export-to-oracle.log I found that the whole php batch file was fully written there.
In fact the php cron was to select data from mysql and just send the result in another oracle table. When I did 'SELECT count(*) FROM ora_table' i keep getting same count result over and over again. But running that same php file at command line sends the data to the appointed oracle table.
WHERE AM I WRONG?,
please help. If someone has come accross this, i'd appreciate if s/he show me the tutorial s/he used to get around this problem
If you're running multiple php scripts, make a file e.g. runphp.sh with the code
...then go to crontab & create cron job:
30 18 * * * sh /path/to/runphp.sh
If just one script, you can run it directly as such:
30 18 * * * php /path/to/script.php
your php file needs to start with and end with the <?php and ?> tags, otherwise it'll just echo it's input (just as is done on the web.
make sure that typing
on the command line works.
I created runphp.sh at /root/runphp.sh
I added php /path/file.php in it
I chmod +x /root/runphp.sh
In the cron, i typed:
30 18 * * * php /path/file.php
Still not executed
However, at command line the php script does what it is supposed to do.
Where am I wrong?
Since you created created runphp.sh at /root/runphp.sh, then in the cron, you should type:
30 18 * * * sh /root/runphp.sh
I did the command exactly as you suggest hereabove and still not working. Where do i read the cron execution error/log file should the script not perform well like in this case? Also, if i specify the minutes less than 10 in the minute part of the cron and write 01 instead of 1 does the zero at the left of 1 matter for script processing?
You may have to export your environment.
on linux terminal type "env"
get the PATH and insert into top of the script calling php:
php -q /whatever/path/to/php/script
The OP's path to php was /usr/bin/php, should not be needed to export anything.
The output of the command in cron is sent to the user who's crontab it is -> check if your local mail works and read it ...
What I've dealt with as a sysadmin years ago was a youngster reading the man pages and getting confused.
I'm wondering if that's not the case here.
What are you doing to add a line to cron ?
crontab -e ?
How do you check what's in your crontab ?
crontab -l ?
[let's hope you know how to use vi]
In the contab you add a line like
30 18 * * * /usr/bin/php /root/command.php
There is no need to add #!/bin/sh or anything like that. (luckily it's a comment in crontabs so you're safe)
The php command as said before needs to start with <?php and end with ?> and should work if invoked from the command line.
If you have trouble getting to know if it runs:
0 * * * * echo "works"
should send you an email once an hour, on the hour. It's sent locally to your account name - so unless you have it configured to send it elsewhere it'll arrive locally.
On thing: I don't use Linux, so its interface to set what cron does might be a bit off from the bsd unix way of doing things.
1) To add a line to a cron i do: crontab -e
2) To see what's in my crontab i do: crontab -l
3) Result of running crontab -l
on my machine is: 02 19 * * * sh /root/runphp.sh. Minutes and hour is changed frequently for testing purposes
4) Content of /root/runphp.sh using vi/vim:
5) File exportMysqlToOracle.php start by <?php and end with ?>
6) permission on /root/runphp.sh as shown by ls -ltr /root/runphp.sh is: -rwxr-xr-x 1 root root 75 Aug 10 16:45 /root/runphp.sh
I don't see what i've missed for this not to work. Please help
"The OP's path to php was /usr/bin/php, should not be needed to export anything."
I recently encountered the same issue and found that cron passes a minimal or even a wrong set of environment variables to jobs.
If you can run the sript from a command line but it fails to run with cron, you have to set environment.
export PATH=/whatever/your/path/is ("env" PATH output)