[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Assign Unix password inside script

Posted on 2007-11-13
5
Medium Priority
?
780 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 375 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

650 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