Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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 02:31 AM. Reason: put tabs in for php

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    New Coder
    Join Date
    Jun 2009
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •