Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Perl script not creating file

Discussion in 'General Discussion' started by MattGarner, Apr 4, 2018.

  1. MattGarner

    MattGarner Registered

    Joined:
    Apr 22, 2016
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    United Kingdom
    cPanel Access Level:
    Root Administrator
    Hi all,

    Could anyone shed some light on where I'm going wrong here?

    So inside /public_html/cgi-bin/ there is a folder called test. In that folder there is a .pl script that contains the following:

    Code:
    #!/usr/bin/perl
    print "Content-type: text/html\n\n";
    open (TEST, ">>/home/$username/public_html/cgi-bin/test/test.txt");
    print TEST "hello world\n";
    close (TEST);
    print "Script finished. Check if file exists.";
    When you visit the .pl script in the browser - The test.txt file isn't created. Although running the script as root on SSH does make script create the file.

    Can anyone help with what is going wrong?
     
  2. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    372
    Likes Received:
    21
    Trophy Points:
    93
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hello,


    Have you checked the Apache error logs for references to the script when attempting to execute it? By default they're located at:

    /usr/local/apache/logs/error_log
     
  3. MattGarner

    MattGarner Registered

    Joined:
    Apr 22, 2016
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    United Kingdom
    cPanel Access Level:
    Root Administrator
    Hi Lauren,

    No entries in the error log by the looks of it.
     
  4. cPanelLauren

    cPanelLauren Forums Analyst
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    372
    Likes Received:
    21
    Trophy Points:
    93
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hi @MattGarner


    I did try this on a test server and found that through the browser I experienced the same behavior. The script executes without issue but does not create a file. I also found that running this via CLI as my user works without issue as well. I would assume if this is the same behavior you're exhibiting that the issue is in the coding of the script itself as there is no error output to the apache error logs that would indicate it was running incorrectly.


    You might also want to seek assistance with the creation of the script:

    System Administration Services | cPanel Forums
     
  5. MattGarner

    MattGarner Registered

    Joined:
    Apr 22, 2016
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    United Kingdom
    cPanel Access Level:
    Root Administrator
    I'm not all that clued up on Perl - Just trying to help someone out. But it seems it's a permissions problem as when the test folder is given 777 and then you try and run the script via the browser the file is then created owned by "nobody". I assume that it can't be dune without 777 or something on the lines of that? Or the code of the perl script is bad.
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    42,734
    Likes Received:
    1,706
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hi Matt,

    Can you verify if the Apache suexec module is installed? If so, you will see output like this:

    Code:
    # rpm -qa|grep suexec
    ea-apache24-mod_suexec-2.4.33-4.4.2.cpanel.x86_64
    If not, try installing the suexec module to see if it makes a difference:

    Code:
    yum install ea-apache24-mod_suexec
    Thank you.
     
Loading...

Share This Page