Solved

Assign Unix password inside script

Posted on 2007-11-13
5
771 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

778 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