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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2005
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow how to execute a bash file from php ?

    hi

    i have a bahs file test in /usr/sbin/

    command is :
    su - root
    password: rootpswd
    /usr/bin/test start

    if i run this command through command line as root login then i am able to run bash file its working fine i.e it starts a server . but when i use
    exec('su - root');
    exec('password: rootpswd' );
    exec('/usr/sbin/test start');

    in php script then i am not getting the output .
    someone plz help me how to execute a bash file from php and how to show the output back to the page .

    thanks in advance for the reply.

  • #2
    New Coder
    Join Date
    Dec 2002
    Location
    Central New York
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Most Likely a Permissions Problem

    ganesh_mak,

    It may not be a problem with PHP, but with the permissions system set up on the server. Remember that scripts processed by PHP are typically done so as "NOBODY". The following may be of use for you:

    http://php.net/manual/en/function.exec.php#59698

    Best of luck!

    -Tim
    Timothy Boronczyk

  • #3
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Putting 'nobody' in sudoers may make the script work but it's really not such a hot idea.

  • #4
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I haven't managed to get PHP to use su correctly yet. First, password: that appears on the screen is a prompt, not a command, so somehow you'd have to echo (the shell command) the password to the correct virtual terminal. You'd probably just have to pipe the output of echo password to /dev/ptysomething. I'll look into experimenting with it later.
    "$question = ( to() ) ? be() : ~be();"

  • #5
    Regular Coder
    Join Date
    Sep 2005
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow

    do i have to change the settings in php.ini to make it work

    safe_mode_exec_dir = path to the script (/var/wwwhtml/rheaserv/)
    safe_mode_include_dir = /usr/sbin/test
    safe_mode_allowed_env_vars = /usr/sbin/test

    when u run the ' /usr/sbin/test start ' it will start asterisk server

    is there anything i have to make change in the php.ini or is it the problem of asterisk ?

  • #6
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you want root access to a certain script, it looks like you'll just have to add a line to /etc/sudoers (using the visudo command) allowing the Apache user the carte blanche to run the command without a password, that way you can just run sudo /usr/sbin/test start and it'll run it as root without question. A bit insecure, but that's about as good as it gets. The include dir for safemode should be the directory, /usr/sbin/ not the actual file.
    "$question = ( to() ) ? be() : ~be();"

  • #7
    New Coder
    Join Date
    Dec 2002
    Location
    Central New York
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ralph l mayo
    Putting 'nobody' in sudoers may make the script work but it's really not such a hot idea.
    Ralph l mayo is correct. Is there any way that you could have the script run without root privilages?

    Or, and I haven't tested this, what about just setting the owner of the file to root, the sticky-bit on the file so that when it executes it will execute with the root permissions and add o+x permissions?

    -Tim
    Timothy Boronczyk


  •  

    Posting Permissions

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