LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-15-2007, 06:36 AM   #1
noir911
Member
 
Registered: Apr 2004
Location: Baltimore, MD
Posts: 681

Rep: Reputation: Disabled
[Perl] Expect.pm local passwd change


I'm trying to change a local user password (UID:500) as root but it doesn't change the password. Here's the script

Code:
#!/usr/bin/perl

use Expect;

# my $user = shift;
# my $password = shift;
my $user = "me";
my $password = "443rfgt";
print "Running 'passwd ${user}'\n";
my $exp = Expect->spawn("passwd ${user}") or die "Can't run 'passwd ${user}'\n";
$exp->expect(500,
              [qr'New UNIX password: $',
               sub {
                 my $fh = shift;
                 $fh->send("${password}\n");
                 print "sent '${password}'\n";
                 exp_continue;
               }
              ],
              [qr'Retype new UNIX password: $',
               sub {
                 my $fh = shift;
                 $fh->send("${password}\n");
                print "sent '${password}'\n";
               }
              ]);
Here's the output -

Quote:
Running 'passwd me'
Changing password for user me.
New UNIX password: sent '443rfgt'

Retype new UNIX password: sent '443rfgt'
 
Old 02-15-2007, 07:39 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,378

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
can i suggest you don't need to use expect chpasswd can accept passsword directly from command line
 
Old 02-16-2007, 06:45 AM   #3
noir911
Member
 
Registered: Apr 2004
Location: Baltimore, MD
Posts: 681

Original Poster
Rep: Reputation: Disabled
This is one way for me to learn Perl. I'm aware of NIST's expect. So, any help in this regard would be appreciated
 
Old 02-16-2007, 07:30 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
Expect is wonderful. I've not used it with Perl though (used TCL/Expect). Is this in a telnet session, or running directly on the machine?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passwd: can't get local yp domain: Local domain name not set powah Linux - Security 4 06-08-2006 09:59 AM
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM
Expect: trivial problem with passwd mallouk Programming 2 05-19-2004 07:21 AM
Searching for GID in /etc/passwd in Perl mimf Linux - General 1 12-03-2003 09:06 AM
qmail doesn't check local users validity through /etc/passwd mimi Linux - Networking 5 07-24-2002 02:50 PM


All times are GMT -5. The time now is 06:14 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration