Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   Shell to perl (http://www.go4expert.com/forums/shell-to-perl-t8983/)

john83reuben 22Feb2008 11:00

Shell to perl
 
I have done a script, but it is based on shell script, and i want to convert it to perl. I am very new to perl.

This is my shell script

#!/bin/bash

echo -n "Enter your name : "
read username
echo -n "Enter your password : "
read password

pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p $pass $username

And i want to change it to perl script

This is how i change it, but it does not work

#!/usr/bin/perl

print "Enter your name : \n";
$username = <STDIN>;
print "Enter your password : \n";
$password = <STDIN>;

$pass=$('print crypt($ARGV[0], "password")' $password)
system("useradd -m -p $pass $username");

PLease help me.

john83reuben 22Feb2008 11:53

Re: Shell to perl
 
I have found the solution.Thanks

#!/usr/bin/perl

print "Enter your name : \n";
$username = <STDIN>;
print "Enter your password : \n";
chomp(my $password = <STDIN>);

$pass = crypt($password,"password");

system("useradd -m -p $pass $username");

pradeep 22Feb2008 13:44

Re: Shell to perl
 
Good that you have found the solution yourself! Happy coding in Perl!


All times are GMT +5.5. The time now is 19:23.