Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 10-25-2005, 03:47 AM   #1
Registered: Dec 2002
Location: us
Posts: 108
Blog Entries: 360

Rep: Reputation: 15
perl script help required to create users and changing the owner to pericular folder

Hi ,

This perl script should ask for username,password to create and home directory .Th important thing is it will cretate a owner for one folder i.e

`chown $ACCOUNT:$ACCOUNT $HOME_DIR/public_html`;
qouta also.

When i try to run this i am getting ERROR

script as follows


# Usage:        $0 <account> <password> <comment>

$version = "2.0";

# definition
$GCOS = $ARGV[2];
$HOME_DIR = "/home/www/"."$ACCOUNT";
$HOME_DIR_FTP = "/home/www/"."$ACCOUNT"."/./";
$SAMPLE_DIR = "/home/www/SAMPLE/*";
$SHELL = "/nosuchshell";

# check args
if ( $ACCOUNT eq "" || $PASSWORD eq "" || $GCOS eq "" ) {
    print "ERROR\n";

        # duplicate check
        if ( 0 ) {
            print "DUPLICATE\n";

                # password encryption
                $CRYPTED_PASSWD = &crypt_passwd($PASSWORD);
                if ( $CRYPTED_PASSWD eq "" ) {
                    print "ERROR\n";

                        # lock

                        # main
                        mkdir("$HOME_DIR", 0755) || die "ERROR\n";
                        `useradd -G ftponly -p "$CRYPTED_PASSWD" -c "$GCOS" -M -d "$HOME_DIR_FTP" -s "$SHELL" $ACCOUNT`;
                        `cp -R $SAMPLE_DIR $HOME_DIR`; 
                         # unlock

                         # return success
                         print "SUCCESS\n";

                         # sub routines
                         sub lock {
                         my ($file) = $_[0];
                         open (LOCK, ">$file");
                           flock(LOCK, 2);

                               sub unlock {
                               my ($file) = $_[0];
                               flock(LOCK, 8);

                             sub crypt_passwd {
                             my ($passwd) = $_[0];
                             my (@letters, $salt, $crypted_passwd);
                             @letters=('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'H', 'J', 'K', 'L', 'M',
                                        'N', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
                                         'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'k', 'm',
                                         'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
                             $salt = "$letters[int(rand(62))]"."$letters[int(rand(62))]";
                             $crypted_passwd = crypt($passwd, $salt);
                             return $crypted_passwd;
Thanks for your help

Last edited by XavierP; 10-25-2005 at 02:16 PM.
Old 10-25-2005, 08:13 AM   #2
Senior Member
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
This belongs in the Programming forum.

Second of all, when there's an error message, post it!

Why are you writing this script when there already are tools that does the job? I'm not suggesting that there are no valid reasons, I just want to know.

And please post all code inside code tags ("[ code ] <your code goes here> [ /code ]", except the spaces near brackets).

Read ESR's `Smart Questions'. It also links to an article about bug reports. Read that too.

Old 10-25-2005, 02:16 PM   #3
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.


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
starting script, init by copy/create file in (samba) folder? muab Linux - General 7 06-22-2005 06:02 PM
writing a script to perform a function on each users mail folder jhill Linux - Newbie 2 08-24-2004 07:18 AM
create users using script polis Linux - General 1 05-18-2004 08:19 AM
perl script to create a backwards file?! WorldBuilder Programming 16 10-30-2003 10:05 PM
Looking for simple way to create scheduled emails from perl script kdowney Programming 1 10-17-2003 06:32 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:38 AM.

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