The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to enforce all users to change their password naw_deepak SUN Solaris 3 06-26-2009 04:51 AM
Help- Change the password of users to common one Tuxidow Shell Programming and Scripting 0 06-11-2009 06:21 AM
how to change root password using shell script with standard password kurva Shell Programming and Scripting 2 02-25-2009 02:35 AM
Modify users password via script? paqman Shell Programming and Scripting 2 08-21-2007 01:22 PM
How do I change users in a script??? chorgan Shell Programming and Scripting 2 02-15-2002 11:53 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2009
dr46014 dr46014 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 95
script to change password for all users

We have a server where we have a number of user ids and we also have the list of old passwords in a CSV file.
Now we want to change the password of all the users and assign them a default password.Can we write a shell script to do that.
I am planning to read the user name and corresponding password from CSV file.But how to login to the server with the same user and change password
with passwd -r file command.
Once i type login the exported paramter values are lost.

Any suggestion or sample script will help.

thanks
Deepak
  #2 (permalink)  
Old 08-24-2009
b33713 b33713 is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 15
with the --stdin option of the command 'passwd',you can do it easily as root

Code:
echo 'the old pass you read from csv file' | passwd --stdin user

post a sample of your csv file,i 'll try
  #3 (permalink)  
Old 08-24-2009
dr46014 dr46014 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 95

Code:
user_id,old_password,new_password
dkrout,P@55word,dk@11word
sdas,P@55word,sd@12word
bkpradhan,P@55word,bk@19word
pthn,P@55word,pt@11word
nsap,P@55word,ns@11word


This is a sample CSV file I am having.I want to change the password to new password.I want to make everythin automated so that after the script run is complete password should change for all users and automated mail will be sent to them.

---------- Post updated at 07:44 PM ---------- Previous update was at 07:17 PM ----------

Quote:
Originally Posted by dr46014 View Post
Code:
user_id,old_password,new_password
dkrout,P@55word,dk@11word
sdas,P@55word,sd@12word
bkpradhan,P@55word,bk@19word
pthn,P@55word,pt@11word
nsap,P@55word,ns@11word


This is a sample CSV file I am having.I want to change the password to new password.I want to make everythin automated so that after the script run is complete password should change for all users and automated mail will be sent to them.
one thing i forgot to mention..i am not the root user.I am an ordinary user who wants to change the password.It is same as loggin in to individaul user using their password and change it and send a mail.To avoid manual work i want to automate it.

Last edited by vgersh99; 08-24-2009 at 10:53 AM.. Reason: code tags, PLEASE!
Bits Awarded / Charged to dr46014 for this Post
Date User Comment Amount
08-24-2009 vgersh99 added code tags - charged 3K bits -3,000
  #4 (permalink)  
Old 08-24-2009
b33713 b33713 is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 15
sorry,i don't know how if you can't access root,i just tried 'sudo',didn't work
i guess its for the security,you need to be root to change others password 'in script'
  #5 (permalink)  
Old 08-24-2009
dr46014 dr46014 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 95
can you frame the script assuming that i am the root user..
i will try to convenience SA team to implement it once the script is ready
  #6 (permalink)  
Old 08-24-2009
b33713 b33713 is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 15

Code:
awk -F, 'NR!=1{system("echo "$3"|passwd --stdin "$1)}' yourCSVfile

and..about the mail,if you changed their passwords,how do they login and check mail without know the new password?hehe
  #7 (permalink)  
Old 08-24-2009
dr46014 dr46014 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 95
Quote:
Originally Posted by b33713 View Post
Code:
awk -F, 'NR!=1{system("echo "$3"|passwd --stdin "$1)}' yourCSVfile

and..about the mail,if you changed their passwords,how do they login and check mail without know the new password?hehe
we can add another column and have the corresponding mail ids ... not unix mail...and use mailx -s .... that is quite possible...i dont understand the use of system here

---------- Post updated at 10:13 PM ---------- Previous update was at 10:09 PM ----------

Quote:
Originally Posted by dr46014 View Post
we can add another column and have the corresponding mail ids ... not unix mail...and use mailx -s .... that is quite possible...i dont understand the use of system here
this is not working in my system ....

---------- Post updated at 10:26 PM ---------- Previous update was at 10:13 PM ----------

Quote:
Originally Posted by dr46014 View Post
we can add another column and have the corresponding mail ids ... not unix mail...and use mailx -s .... that is quite possible...i dont understand the use of system here

---------- Post updated at 10:13 PM ---------- Previous update was at 10:09 PM ----------



this is not working in my system ....
won't this ask for old password and confirmation password if i am running it from root..as i dont have that access its not working .....
will it work in Sun Solaris too ??
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0