nixCraft Linux Forum

nixCraft

Linux 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

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 12-29-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
Sponsored Links
  #2 (permalink)  
Old 01-01-2006, 01:50 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 906
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 | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 11-15-2007, 09:36 AM
Junior Member
User
 
Join Date: Nov 2007
My distro: Fedora
Posts: 4
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 11-15-2007, 02:57 PM
Junior Member
User
 
Join Date: Nov 2007
My distro: Fedora
Posts: 4
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 11-18-2007, 08:35 AM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 481
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
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 11-26-2007, 03:56 PM
Junior Member
User
 
Join Date: Nov 2007
My distro: Fedora
Posts: 4
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 11-26-2007, 04:02 PM
Junior Member
User
 
Join Date: Nov 2007
My distro: Fedora
Posts: 4
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 06-09-2008, 04:06 PM
Member
User
 
Join Date: Oct 2007
My distro: Linux RHEL 5
Posts: 33
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 06-13-2008, 11:01 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 906
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 | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks


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 On

Similar Threads

Thread Thread Starter Forum Replies Last Post
how to change root password sandromax Solaris/OpenSolaris 4 10-11-2007 02:43 AM
let users change password using perl script? james bond Getting started tutorials 9 05-24-2007 10:32 PM
Change root password MySQL 5 chiku Databases servers 1 01-16-2007 08:46 PM
HP UX user lock password, change password, password aging rockdalinux HP-UX 0 12-20-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 06:11 AM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

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