nuebelhor
11-05-2009, 02:29 AM
Hello all,
First I'm using a Linux computer and trying to write commands into php script to copy a file from one directory to another.
Been trying different things to no avail, would seem might be a simple fix...trying to just copy a file that will have a different filename every hour over to a generic filename already saved in a different directory and save over old data in the file using PHP script. Actually works when I run manually...but not when ran using crontab, not sure why other than maybe $remote_file doesn't have permissions or something and will only copy when I run it manually? Any simple fix for this?
Been trying to use the system command,
$copy = "scp /usr/local/$remote_file /usr/local/profiler/bby.txt";
system($copy);
Also tried calling a seperate shell_script
system(/usr/local/shell_scripts/send_file.sh $remote_file);
Then shell script has same command as above.
Any help appreciated! Thanks
Fou-Lu
11-05-2009, 02:53 AM
PHP has a rename() function. It wants full file paths from and to.
If its working from the browser, but failing from the crontab, I'd suspect filepermissions are to blame.
I also assume that $remote_file is somehow declared and valid.
Also, you will find that system, exec and `` are often disabled for security reasons in PHP.
oesxyl
11-05-2009, 02:57 AM
put this at the begining of the file and see what's happend:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
crontab scripts run in another envirioment then usual you have in the shell.
I don't understand why do you need php for this job.
best regards
oesxyl
11-05-2009, 02:59 AM
PHP has a rename() function. It wants full file paths from and to.
If its working from the browser, but failing from the crontab, I'd suspect filepermissions are to blame.
I also assume that $remote_file is somehow declared and valid.
Also, you will find that system, exec and `` are often disabled for security reasons in PHP.
op use scp, is probably a network disk mounted somewhere, :)
best regards
Fou-Lu
11-05-2009, 03:00 AM
put this at the begining of the file and see what's happend:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
crontab scripts run in another envirioment then usual you have in the shell.
I don't understand why do you need php for this job.
best regards
Yeah, I was thinking the exact thing on this one as well. Except, using PHP does give the benefit of being able to handle poor-mans cron, but I don't think thats really an issue nowadays.
Oh, also I assumed that the crontab is actually executing the PHP command first.
nuebelhor
11-05-2009, 04:10 AM
PHP has a rename() function. It wants full file paths from and to.
If its working from the browser, but failing from the crontab, I'd suspect filepermissions are to blame.
I also assume that $remote_file is somehow declared and valid.
Also, you will find that system, exec and `` are often disabled for security reasons in PHP.
Fou-Lu...tried the rename() function but same thing happens works when I run it manually or just run the shell. Try to write something like a chmod 777 file_name into the code to give it permissions but does not work. Any other way to give it permissions to grab the file? Thanks
Fou-Lu
11-05-2009, 04:35 AM
Methinks an ownership/permission problem. Oesxyl will probably be able to help you more on this issue; he knows linux a lot better than I. Who made the file, was it a manual creation or was it created through php via Apache?
Running it manually, I assume you mean served through apache? And for shell, are you using root or the same user executing the cron job?
Also, I assume you're commanding you're cron with something like /usr/bin/php or wherever you're PHP is located?
oesxyl
11-05-2009, 03:14 PM
Methinks an ownership/permission problem. Oesxyl will probably be able to help you more on this issue; he knows linux a lot better than I
I don't think I can help op since don't provide enough information.
This seems to be a old problem( op have another thread with some subject, similar at least).
best regards