Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 11-05-2009, 03:29 AM   PM User | #1
nuebelhor
New Coder

 
Join Date: Jun 2009
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
nuebelhor is an unknown quantity at this point
Linux: SCP file to diff directory/change filename using PHP or call sh script fm PHP

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,

PHP Code:
$copy "scp /usr/local/$remote_file /usr/local/profiler/bby.txt";
system($copy); 
Also tried calling a seperate shell_script

PHP Code:
system(/usr/local/shell_scripts/send_file.sh $remote_file); 
Then shell script has same command as above.

Any help appreciated! Thanks

Last edited by nuebelhor; 11-05-2009 at 03:31 AM.. Reason: put tabs in for php
nuebelhor is offline   Reply With Quote
Old 11-05-2009, 03:53 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 5,123
Thanks: 2
Thanked 554 Times in 542 Posts
Fou-Lu is a jewel in the roughFou-Lu is a jewel in the roughFou-Lu is a jewel in the rough
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.
__________________
Code:
struct User *upFou;
userInit(upFou, "Fou-Lu", 1);
printf("%s has %s to %s\n", (*upFou).Name, !quitSmoking(upFou) ? "FAILED" : "SUCCEEDED", (*upFou).Smoker == 1 ? "FAIL" : "PASS");
// Fou-Lu has FAILED to FAIL?  Lol
Fou-Lu is offline   Reply With Quote
Old 11-05-2009, 03:57 AM   PM User | #3
oesxyl
Senior Coder


 
Join Date: Dec 2007
Posts: 4,658
Thanks: 374
Thanked 562 Times in 551 Posts
oesxyl has a spectacular aura aboutoesxyl has a spectacular aura about
put this at the begining of the file and see what's happend:
PHP Code:
<?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 is offline   Reply With Quote
Old 11-05-2009, 03:59 AM   PM User | #4
oesxyl
Senior Coder


 
Join Date: Dec 2007
Posts: 4,658
Thanks: 374
Thanked 562 Times in 551 Posts
oesxyl has a spectacular aura aboutoesxyl has a spectacular aura about
Quote:
Originally Posted by Fou-Lu View Post
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
oesxyl is offline   Reply With Quote
Old 11-05-2009, 04:00 AM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 5,123
Thanks: 2
Thanked 554 Times in 542 Posts
Fou-Lu is a jewel in the roughFou-Lu is a jewel in the roughFou-Lu is a jewel in the rough
Quote:
Originally Posted by oesxyl View Post
put this at the begining of the file and see what's happend:
PHP Code:
<?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.
__________________
Code:
struct User *upFou;
userInit(upFou, "Fou-Lu", 1);
printf("%s has %s to %s\n", (*upFou).Name, !quitSmoking(upFou) ? "FAILED" : "SUCCEEDED", (*upFou).Smoker == 1 ? "FAIL" : "PASS");
// Fou-Lu has FAILED to FAIL?  Lol
Fou-Lu is offline   Reply With Quote
Old 11-05-2009, 05:10 AM   PM User | #6
nuebelhor
New Coder

 
Join Date: Jun 2009
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
nuebelhor is an unknown quantity at this point
rename() function

Quote:
Originally Posted by Fou-Lu View Post
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
nuebelhor is offline   Reply With Quote
Old 11-05-2009, 05:35 AM   PM User | #7
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 5,123
Thanks: 2
Thanked 554 Times in 542 Posts
Fou-Lu is a jewel in the roughFou-Lu is a jewel in the roughFou-Lu is a jewel in the rough
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?
__________________
Code:
struct User *upFou;
userInit(upFou, "Fou-Lu", 1);
printf("%s has %s to %s\n", (*upFou).Name, !quitSmoking(upFou) ? "FAILED" : "SUCCEEDED", (*upFou).Smoker == 1 ? "FAIL" : "PASS");
// Fou-Lu has FAILED to FAIL?  Lol
Fou-Lu is offline   Reply With Quote
Old 11-05-2009, 04:14 PM   PM User | #8
oesxyl
Senior Coder


 
Join Date: Dec 2007
Posts: 4,658
Thanks: 374
Thanked 562 Times in 551 Posts
oesxyl has a spectacular aura aboutoesxyl has a spectacular aura about
Quote:
Originally Posted by Fou-Lu View Post
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
oesxyl is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:20 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.