RAID status using php - Mandriva

This is a discussion on RAID status using php - Mandriva ; Hi, I want to write a simple php program to show the user the status of the RAID array on the system. The user is not linux literate so I want to make it as idiot proof as possible. Not ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: RAID status using php

  1. RAID status using php

    Hi,

    I want to write a simple php program to show the user the status of the
    RAID array on the system. The user is not linux literate so I want to
    make it as idiot proof as possible. Not that I'm much better ;>)

    The command: dmraid -r displays the raid status.

    I'm using the php passthru() function to display the result of the above
    command on a web page.

    Here's a snippet from the php script to demonstrate that this doesn't
    work from php.


    echo '
    ';

    // this works and outputs several lines of text
    passthru('ls -l',$retval);

    // return value=0 (success)
    echo '
    '.$retval;

    echo '
    ';

    // this outputs nothing
    passthru('dmraid -r',$retval);

    // return value=1 (error)
    echo '
    '.$retval;

    exit();
    echo '
    ';
    ?>

    So why does passthru('ls -l') work and passthru('dmraid -r') not work?

    Thanks,


    Frank



  2. Re: RAID status using php



    Frank Dreyfus wrote:
    > Hi,
    >
    > I want to write a simple php program to show the user the status of the
    > RAID array on the system. The user is not linux literate so I want to
    > make it as idiot proof as possible. Not that I'm much better ;>)
    >
    > The command: dmraid -r displays the raid status.
    >
    > I'm using the php passthru() function to display the result of the above
    > command on a web page.
    >
    > Here's a snippet from the php script to demonstrate that this doesn't
    > work from php.
    >
    >
    > > echo '
    ';
    >
    > // this works and outputs several lines of text
    > passthru('ls -l',$retval);
    >
    > // return value=0 (success)
    > echo '
    '.$retval;
    >
    > echo '
    ';
    >
    > // this outputs nothing
    > passthru('dmraid -r',$retval);
    >
    > // return value=1 (error)
    > echo '
    '.$retval;
    >
    > exit();
    > echo '
    ';
    > ?>
    >
    > So why does passthru('ls -l') work and passthru('dmraid -r') not work?
    >
    > Thanks,
    >
    >
    > Frank
    >
    >

    may I sugest makeing dmraid -r output to a text file then picking up the
    file after created then deleating the file

    maby dmraid -r is outputing to sterr insted of stout.

    then maby you could post the working php here, I could use somthing like
    that on my server.

  3. Re: RAID status using php

    On Mon, 18 Feb 2008 22:33:35 -0500, Frank Dreyfus wrote:

    > // this outputs nothing
    > passthru('dmraid -r',$retval);


    dmraid resides in /sbin, requires root auth as it can be used to activate
    or deactivate raid sets.

    I think you could set up a symlink to /sbin/dmraid in /usb/bin, and add
    a /etc/sudoers entry to allow "dmraid -r", to run as root, without a
    password. Make sure it only allows the -r option. Test it thourghly .

    I still find the sudoers file a mess to figure out.

    Regards, Dave Hodgins

    --
    Change nomail.afraid.org to ody.ca to reply by email.
    (nomail.afraid.org has been set up specifically for
    use in usenet. Feel free to use it yourself.)

  4. Re: RAID status using php

    "David W. Hodgins" wrote in
    newsp.t6rvovlaa3w0dx@hodgins.homeip.net:

    > I think you could set up a symlink to /sbin/dmraid in /usb/bin, and add
    > a /etc/sudoers entry to allow "dmraid -r", to run as root, without a
    > password.


    Thanks again Dave,

    I'll be out of the office today but will give it a try tonight.


    Thanks,


    Frank

  5. Re: RAID status using php

    chris gareau wrote in news:qnuuj.54910$Ly.25440@pd7urf1no:


    Hi Chris,

    > may I sugest makeing dmraid -r output to a text file then picking up
    > the file after created then deleating the file
    >
    > maby dmraid -r is outputing to sterr insted of stout.
    >


    I had tried that but with no joy.

    > then maby you could post the working php here, I could use somthing
    > like that on my server.
    >


    Will do.

    Frank

  6. Re: RAID status using php -- SUCCESS!

    Frank Dreyfus wrote in
    news:Xns9A48E57E31554adfslur0mdoaur03jadl@207.115. 17.102:

    > Hi,
    >
    > I want to write a simple php program to show the user the status of the
    > RAID array on the system. The user is not linux literate so I want to
    > make it as idiot proof as possible. Not that I'm much better ;>)
    >
    > The command: dmraid -r displays the raid status.
    >
    > I'm using the php passthru() function to display the result of the

    above
    > command on a web page.
    >
    > Here's a snippet from the php script to demonstrate that this doesn't
    > work from php.
    >
    >
    > > echo '
    ';
    >
    > // this works and outputs several lines of text
    > passthru('ls -l',$retval);
    >
    > // return value=0 (success)
    > echo '
    '.$retval;
    >
    > echo '
    ';
    >
    > // this outputs nothing
    > passthru('dmraid -r',$retval);
    >
    > // return value=1 (error)
    > echo '
    '.$retval;
    >
    > exit();
    > echo '
    ';
    > ?>
    >
    > So why does passthru('ls -l') work and passthru('dmraid -r') not work?
    >
    > Thanks,
    >
    >
    > Frank
    >
    >
    >


    OK, It works!

    Here's how to do it.

    1. Add a line to /etc/sudoers as follows:
    apache = NOPASSWD: /sbin/dmraid -r

    This permits user apache to run dmraid -r and ONLY dmraid with the -r
    parameter. Thanks to the NOPASSWD: directive, sudo doesn't ask for a
    password.

    Note: substitute your host name for .

    2. Incorporate this php snippet into your web page.
    echo '
    ';
    passthru('sudo dmraid -r',$retval);

    exit(); //I don't think this line is needed but it doesn't hurt
    echo '
    ';
    ?>

    That's it.

    Works very nicely.

    Thanks David for pointing me in the right direction and thanks Bit
    Twister for helping me out with sudo.

    Frank

+ Reply to Thread