Find the answer to your Linux question:
Results 1 to 2 of 2
hi, i want to change the password of root by non-root user using shell file. i am trying echo user_password | sudo passwd --stdin root here user_password is the password ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2003
    Posts
    3

    URGENT-Help for Shell Scripting


    hi,

    i want to change the password of root by non-root user using shell file.
    i am trying
    echo user_password | sudo passwd --stdin root

    here user_password is the password entered by the user

    it works fine from the command line, but from shell i am trying

    echo $1 | sudo passwd --stdin root

    and it just prints the
    $1 | sudo passwd --stdin root

    solution to this problem will be highly appreciated.

    thanx
    vishal angrish

  2. #2
    Linux Engineer
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    796
    With the echo command you tells the shell just to print it out on standard output... try this one..

    Code:
    #!/bin/sh
    
    if [ -z $1 ]
       then
       echo "You must specifie something after $0"
       exit 1
    else
       echo "Executing $1 to sudo passwd --stdin root"
       echo $1 | sudo passwd --stdin root 
    
       if [ $? = 0 ]
          then
          echo "Wow it seemed to work.."
       else
          echo "Oops the Sudo passwd command failed."
          exit 1
       fi
    fi
    Regards

    Andutt

Posting Permissions

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