LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 10-25-2005, 03:47 AM   #1
sridhar11
Member
 
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

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

When i try to run this i am getting ERROR

script as follows

#!/usr/bin/perl

#===============================================================================
# Usage:        $0 <account> <password> <comment>
# Return:       SUCCESS | DUPULICATE | ERROR
#
#===============================================================================

$version = "2.0";

#------------
# definition
#------------
$ACCOUNT = $ARGV[0];
$PASSWORD = $ARGV[1];
$GCOS = $ARGV[2];
$HOME_DIR = "/home/www/"."$ACCOUNT";
$HOME_DIR_FTP = "/home/www/"."$ACCOUNT"."/./";
$SAMPLE_DIR = "/home/www/SAMPLE/*";
$SHELL = "/nosuchshell";
$LOCK_FILE="/user/scripts/www/.webspace.lock";

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

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

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

                        #------
                        # lock
                        #------
                        &lock($LOCK_FILE);

                        #------
                        # 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
                         #--------
                         &unlock($LOCK_FILE);

                         #----------------
                         # return success
                         #----------------
                         print "SUCCESS\n";
                         exit;

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

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

                             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');
                                        srand();
                             $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
jonaskoelker
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.

--Jonas
 
Old 10-25-2005, 02:16 PM   #3
XavierP
Moderator
 
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.
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:57 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
Open Source Consulting | Domain Registration