Solved

Assign Unix password inside script

Posted on 2007-11-13
5
772 Views
Last Modified: 2013-12-26
I want to assign a default password for all of the newly create unix account inside a script so that I don't need to assign for them one-by-one.
0
Comment
Question by:HenryChang
  • 3
5 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 20277710
You'll need to use an expect script (Install expect from sunfreeware.com if you don't already have it).

The script would look like

#/usr/local/bin/expect
spawn passwd [lindex $argv 0]
expect "New Password:"
send "password\r"
expect "Re0enter new Password:"
send "password\r"
expect eof
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20277712
Small typo.

expect "Re0enter new Password:"

should be

expect "Re-enter new Password:"
0
 

Author Comment

by:HenryChang
ID: 20278127
Hi,
Can you send the whole script to me?  I have download the relevant softwares..  My script is :

root@hkgss1100043:/root>cat test
/usr/local/bin/expect
spawn passwd [lindex $argv 0]
expect "New Password:"
send "password\r"
expect "Re-enter new Password:"
send "password\r"
expect eof


Thanks a lot

0
 
LVL 48

Accepted Solution

by:
Tintin earned 125 total points
ID: 20278147
Just wrap it in shell, eg:

#!/bin/sh
for user in `cat list_of_users.txt`
do
  echo "Setting default password for $user"
  /path/to/passwd.exp $user
done
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20280174
Hi,

 HenryChang,

I think you missed #! in front of /usr/local/bin/expect in your script. So change it to:

#!/usr/local/bin/expect
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question