nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Change root password using perl script?

This is a discussion on Change root password using perl script? within the Solaris/OpenSolaris forums, part of the UNIX operating systems category; I would like to change password using perl script... any idea how to do it? -Raj...


Go Back   nixCraft Linux Forum > UNIX operating systems > Solaris/OpenSolaris

Linux answers from nixCraft.


Solaris/OpenSolaris Discuss all about the SUN Solairs/OpenSolaris. You are free to talk about any issues related to Solaris administration, networking, services and other stuff, share information or ask doubts.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 29-12-2005, 10:27 PM
Raj1
Guest
 
Posts: n/a
Default Change root password using perl script?

I would like to change password using perl script... any idea how to do it?

-Raj
Reply With Quote
  #2 (permalink)  
Old 01-01-2006, 01:50 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,709
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

You really don't need a perl script. All you need is following shell script and expect tool:
Code:
vi npasswd
Add following lines to it:
Code:
#!/bin/sh
# \
exec expect -f "$0" ${1+"$@"}
set password [lindex $argv 1]
spawn passwd [lindex $argv 0]
expect "assword:"
send "$password\r"
expect "assword:"
send "$password\r"
expect eof
To change password for user vivek:
Code:
npasswd vivek 123456
Where,
npasswd : script name
vivek : username
123456: Newpassword

Script must be run as a root user, it can be call from perl, php or any other lanauge. Download expect tool here: http://expect.nist.gov/
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 15-11-2007, 09:36 AM
Junior Member
User
 
Join Date: Nov 2007
OS: Fedora
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
pmtsampath is on a distinguished road
Default How to download Tcl

Hi i tried to install expect, but it required Tcl..
From where i can download the Tcl..?
Reply With Quote
  #4 (permalink)  
Old 15-11-2007, 02:57 PM
Junior Member
User
 
Join Date: Nov 2007
OS: Fedora
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
pmtsampath is on a distinguished road
Default Cant able to install expect

Hi i download expect and Tcl and store it in the path /usr/local/src.
But while run ./configure file, it was unable to detect the Tcl file..
How to install the expect..?
Reply With Quote
  #5 (permalink)  
Old 18-11-2007, 08:35 AM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
OS: Debian GNU/Linux
Posts: 506
Thanks: 0
Thanked 8 Times in 6 Posts
Rep Power: 7
monk has a spectacular aura about monk has a spectacular aura about
Default

Use the Unix::PasswdFile module (cpan module), it provides an abstract interface to /etc/passwd format files. It automatically handles file locking, getting colons in the right places, and all the other niggling details.

Code to change password for monk user:
Code:
#!/usr/bin/perl 
use Unix::PasswdFile;

$pw = new Unix::PasswdFile "/etc/passwd";
$pw->passwd("monk", $pw->encpass("My-New-Password"));
$pw->commit();
undef $pw;
function passwd( USERNAME [,PASSWD] )
It can read or modify a user's password. Returns the encrypted password in either case. If you have a plaintext password, use the encpass method to encrypt it before passing it to this method. Refer to man page for more details
__________________
May the force with you!
Reply With Quote
  #6 (permalink)  
Old 26-11-2007, 03:56 PM
Junior Member
User
 
Join Date: Nov 2007
OS: Fedora
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
pmtsampath is on a distinguished road
Default Change root password using perl script?

Thank you..
I'd change the root password from perl script.
Reply With Quote
  #7 (permalink)  
Old 26-11-2007, 04:02 PM
Junior Member
User
 
Join Date: Nov 2007
OS: Fedora
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
pmtsampath is on a distinguished road
Default Change xml to html code

Hi,
I want to change xml coding to html coding.
Is there any option to draw circle in html?
Reply With Quote
  #8 (permalink)  
Old 09-06-2008, 04:06 PM
Member
User
 
Join Date: Oct 2007
OS: Linux RHEL 5
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
vikas027 is on a distinguished road
Exclamation

Quote:
Originally Posted by monk View Post
Use the Unix::PasswdFile module (cpan module), it provides an abstract interface to /etc/passwd format files. It automatically handles file locking, getting colons in the right places, and all the other niggling details.

Code to change password for monk user:
Code:
#!/usr/bin/perl 
use Unix::PasswdFile;

$pw = new Unix::PasswdFile "/etc/passwd";
$pw->passwd("monk", $pw->encpass("My-New-Password"));
$pw->commit();
undef $pw;
function passwd( USERNAME [,PASSWD] )
It can read or modify a user's password. Returns the encrypted password in either case. If you have a plaintext password, use the encpass method to encrypt it before passing it to this method. Refer to man page for more details

Hi Monk,

Can you pls tell me how to run this script. I am completely nuts abt perl.

THanks,
VIKAS
Reply With Quote
  #9 (permalink)  
Old 13-06-2008, 11:01 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,709
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Quote:
Originally Posted by vikas027 View Post
Hi Monk,

Can you pls tell me how to run this script. I am completely nuts abt perl.

THanks,
VIKAS
You need to have perl installed. You also need to have Unix::PasswdFile cpan module installed on Solaris UNIX. This can be done using package manager.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
how to change root password sandromax Solaris/OpenSolaris 4 11-10-2007 02:43 AM
let users change password using perl script? james bond Getting started tutorials 9 24-05-2007 10:32 PM
Change root password MySQL 5 chiku Databases servers 1 16-01-2007 08:46 PM
HP UX user lock password, change password, password aging rockdalinux HP-UX 0 20-12-2006 02:36 PM
How to Change Password puppen Linux software 6 06-06-2006 01:56 PM


All times are GMT +5.5. The time now is 12:16 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38