LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-06-2014, 01:05 PM   #1
saahil27
LQ Newbie
 
Registered: Mar 2014
Posts: 1

Rep: Reputation: Disabled
Unable to create user using perl script


Hello everyone,

I am new to perl scripting and still learning any how just for practice purpose I am trying to create a script which can create user along with encrypted password.

I managed to do so with the below script

Code:
#!/usr/bin/perl -w

my $useradd="/usr/sbin/useradd";
my $passwd="/usr/bin/passwd";
my $chmod="/bin/chmod";

# Total no. of users to be created
$count= 10;

# Users should be created using root account
if ( `id -u` == 0 )
{

# List of commands to be executed for new user
do {
        print "Enter username: ";
        chomp ($user=<STDIN>);

# Verify if user exists
        `grep $user /etc/passwd > /dev/null`;

if ( $? == 0) {
        print "The $user already exists\n";
        exit 1;
}

else {

        print "Enter password: ";
        chomp ($password=<STDIN>);
        $pass=`perl -e 'print crypt("$password", "salt")'`;


if ( $? != 0 ) {
print "Password is not proper\n\n";
exit 1;
}
else {
        `$useradd -p $pass $user`;

        print "User $user created\n\n";
        print "Changing permission for $user\'s home directory to 755\n\n";
        `$chmod 700 /home/$user`;

        }
}
}
until ($count == 0);
}

else {
        print "User is not root\n";

}
Well the problem is the script works fine if I use a normal password (non alpha numeric) but when I use a alphanumeric password for ex abcd@123#

Though the script runs correctly but I am unable to login with that user as it says "Password Incorrect"

I am not sure why I am getting this message while the same works very smoothly with normal password like "abcd123"

Am I doing something incorrect?
 
Old 03-06-2014, 03:42 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Two things:
  1. No idea about the root cause of your issue. But I would start troubleshooting by creating a simple perl / crypt program and comparing resulting digests with a system crypt(3) digest. They should match; but who knows what subtleties we're missing in your code.
  2. I would point out that you're not really writing a perl program. You're writing a wrapper around the shell. And I would argue - in this case - the job may be better suited for bash itself.
 
  


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
how i can make script bash or perl to create vps ? a_1 Linux - Server 5 11-15-2012 08:34 AM
[SOLVED] Create a file with suid from Perl script rafiki8 Programming 4 05-14-2012 10:17 AM
Help create perl script for delete file/folder sportivo888 Linux - Newbie 5 12-06-2007 12:33 AM
perl script to create a backwards file?! WorldBuilder Programming 16 10-30-2003 11:05 PM
Looking for simple way to create scheduled emails from perl script kdowney Programming 1 10-17-2003 07:32 PM


All times are GMT -5. The time now is 06:58 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration