Find the answer to your Linux question:
Results 1 to 7 of 7
I am not much the scripter and I was hoping for some help by the shell geniuses out there. My web host runs PHP as a cgi through phpsuexec. They ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! T313C0mun1s7's Avatar
    Join Date
    Aug 2006
    Posts
    4

    shell scripting the copy of same file to full tree


    I am not much the scripter and I was hoping for some help by the shell geniuses out there. My web host runs PHP as a cgi through phpsuexec. They also have register_globals as on by default. The consequences of this is that the normal method to override this setting will not work. Normally a person could do this with an option in the .htaccess file in the root of the directory you wish to effect, and it effects of the option change filter down recursively to all subdirectories. Well I have a PHP script that behaves very badly if register_globals is on. The override under the phpsuexec system is a php.ini file IN EVERY DIRECTORY IT NEEDS TO EFFECT. Fortunately, my host gives me SSH shell access.

    So what I am hoping for is a shell script or PHP script that will allow me to copy my php.ini file recursively to every folder from my chosen root.

    Any Takers??

  2. #2
    Linux Enthusiast KenJackson's Avatar
    Join Date
    Jun 2006
    Location
    Maryland, USA
    Posts
    510
    If you want it in every subdirectory, just do it from the command line like this. The '-i' on cp will cause it to prompt you before overwriting an existing file.
    Code:
    $ for dir in $(find . -type d); do cp -i php.ini $dir; done

  3. #3
    Just Joined! T313C0mun1s7's Avatar
    Join Date
    Aug 2006
    Posts
    4
    Thank you for the reply. This command net me a response from the shell of:

    Code:
    -jailshell: syntax error near unexpected token `do'

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Enthusiast KenJackson's Avatar
    Join Date
    Jun 2006
    Location
    Maryland, USA
    Posts
    510
    As a test I just ran this command in my SSH bash shell at my BlueHost-hosted site and it worked fine:
    Code:
    for dir in $(find . -type d); do echo $dir; done
    I think jailshell is a limited shell used by cPanel. It seems to be the problem. I don't know it's limitations.
    Maybe this would work
    Code:
    find . -type d | while read dir; do cp -i php.ini $dir; done

  6. #5
    Just Joined! T313C0mun1s7's Avatar
    Join Date
    Aug 2006
    Posts
    4
    Quote Originally Posted by KenJackson
    As a test I just ran this command in my SSH bash shell at my BlueHost-hosted site and it worked fine:
    Code:
    for dir in $(find . -type d); do echo $dir; done
    I think jailshell is a limited shell used by cPanel. It seems to be the problem. I don't know it's limitations.
    Maybe this would work
    Code:
    find . -type d | while read dir; do cp -i php.ini $dir; done
    I tried the first option and it worked for me. Thank you very much. I did not try the second as the first worked.

    I was not using cPanel, but rather I was SSHed into a shell from a term window. So I do not know what jailshell is either. However, my host does use cPanel, but they are very security conscious. I have to sign an affidavit and pay $25 for shell access via SSH, and PHP is setup as cgi through phpsuexec.

    [ramble]
    It took me a little bit to learn how to get phpsuexec to play nice with some scripts that claim it really won't work well under (like ZenCart), but it wasn't too bad and things run fine now. All you need to do is make sure the max permissions on directories and files is 755 (777 generates a 500 internal server error) and generally you can set directories at 755 and files at 644 and be fine. It seems a lot of scripts seem to think they need higher permissions than they really do. For example they always say to set the upload directory to 777, why does the upload directory need execute permissions?
    [/ramble]

  7. #6
    Linux Enthusiast KenJackson's Avatar
    Join Date
    Jun 2006
    Location
    Maryland, USA
    Posts
    510
    Well it sounds like you got it to work. But I already thought of a different solution that doesn't require a loop, so I'll mention it anyway. Note the space after the period on the second line.
    Code:
    find . -type d -fprintf copyphp "cp -i php.ini %p\n"
    . copyphp
    rm copyphp

  8. #7
    Just Joined! T313C0mun1s7's Avatar
    Join Date
    Aug 2006
    Posts
    4
    I know there is sure some serious power in the shell, but I just don't know how to tap into it. I looks as if you do though.

    I just have not had time or occasion to learn, and I am not a scripting type person to begin with. I might learn now though, as I have given up on Windows™ and have been using Ubuntu exclusively for three months now. I have Dreamweaver 8 installed via Wine, and VMWare server so I can use Photoshop CS2, but that is about it. I am still looking for a good FTP client. gFTP sucks, it just dies out of no where, the Linux nightly of FileZilla is functional and fast as hell, but it is feature light and the interface leaves something to be desired. I sure would like to find a robust feature rich FTP client like AbsoluteFTP on Windows™

    Thanks again for you help.

Posting Permissions

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