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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-25-2005, 03:47 AM
|
#1
|
Member
Registered: Dec 2002
Location: us
Posts: 108
Rep:
|
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.
|
|
|
10-25-2005, 08:13 AM
|
#2
|
Senior Member
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524
Rep:
|
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
|
|
|
10-25-2005, 02:16 PM
|
#3
|
Moderator
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
|
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
|
|
|
All times are GMT -5. The time now is 11:57 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|