• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 783
  • Last Modified:

Assign Unix password inside script

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
HenryChang
Asked:
HenryChang
  • 3
1 Solution
 
TintinCommented:
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
 
TintinCommented:
Small typo.

expect "Re0enter new Password:"

should be

expect "Re-enter new Password:"
0
 
HenryChangAuthor Commented:
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
 
TintinCommented:
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
 
omarfaridCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now