[Webinar] Streamline your web hosting managementRegister Today

x
  • 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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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