SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,104
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    shell_exec advice needed

    Hi all,

    I want this script to change the root pass and user pass on a linux server.
    The commands work from the command line but before I run this php script on my server, I want to make sure I don't lock myself out.

    Can someone take a look and give a thumbs up or down.

    PHP Code:
    $path_to_dir '/usr/local/pass';
    $cmd "cd $path_to_dir; ";
    //$cmd .= "ls -l"; // this verifies I am in the correct directory

    $userpass 'secret';

    $cmd .= shell_exec('sudo ./passupdate root '.$userpass);
    $cmd .= shell_exec('sudo ./passupdate user '.$userpass);


    $result shell_exec($cmd); 
    passupdate resides in '/usr/local/pass'

    I'm wondering if I need a \n after $userpass

    Thanks for looking and apreciate any input.
    What I lack in acuracy I make up for in misteaks

  2. #2
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,104
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    followup, it worked and I am not locked out.

    changed to
    PHP Code:
    $cmd .= shell_exec(" sudo ../../../usr/local/pass/passupdate root $userpass\r\n"); 
    passupdate is,
    Code:
    #!/bin/sh
    # \
    exec expect -f "$0" ${1+"$@"}
    set password [lindex $argv 1]
    spawn passwd [lindex $argv 0]
    expect "assword:"
    send "$password\r"
    expect "assword:"
    send "$password\r"
    expect eof
    This needs to have "expect" installed to work.

    Thank you for looking
    cheers
    LW
    What I lack in acuracy I make up for in misteaks


Bookmarks

Posting Permissions

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