Shell to perl

Discussion in 'Perl' started by john83reuben, Feb 22, 2008.

  1. john83reuben

    john83reuben New Member

    Joined:
    Feb 19, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. john83reuben

    john83reuben New Member

    Joined:
    Feb 19, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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");
     
  3. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Good that you have found the solution yourself! Happy coding in Perl!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice