Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > [SortofNewbie] Addusers with script on crontab

Reply
Thread Tools

[SortofNewbie] Addusers with script on crontab

 
 
Henk
Guest
Posts: n/a
 
      06-24-2004
Ok guy's i need some help i have to create allot of users on an new
webserver (also the must have ftp access vistualhost and so on) i've got an
script allready but there comes an new user (and here it comes) i don't know
how to check if the username already exists in linux and perl how can i do
this ? is there any one who allready has done thius please show me an
snippet of that code

Many thnx...


 
Reply With Quote
 
 
 
 
Henk
Guest
Posts: n/a
 
      06-24-2004

"Gunnar Hjalmarsson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Henk wrote:
> > Ok guy's i need some help i have to create allot of users on an new
> > webserver (also the must have ftp access vistualhost and so on)
> > i've got an script allready but there comes an new user (and here
> > it comes) i don't know how to check if the username already exists
> > in linux and perl how can i do this ? is there any one who allready
> > has done thius please show me an snippet of that code

>
> Unfortunately I don't have such a script.
>
> Where can I sign up for an account on your server?
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl


That's a shame ;(
Sorry but u can't sign up for it (yet ) it's for an private collage
network
btw.. sorry for the crappy english but i hope you all understand what i am
trying to write here


 
Reply With Quote
 
 
 
 
Henk
Guest
Posts: n/a
 
      06-24-2004

"Henk" <(E-Mail Removed)> wrote in message
news:40db1a8f$1_10@Output.100ProofNews.com...
>
> "Gunnar Hjalmarsson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Henk wrote:
> > > Ok guy's i need some help i have to create allot of users on an new
> > > webserver (also the must have ftp access vistualhost and so on)
> > > i've got an script allready but there comes an new user (and here
> > > it comes) i don't know how to check if the username already exists
> > > in linux and perl how can i do this ? is there any one who allready
> > > has done thius please show me an snippet of that code

> >
> > Unfortunately I don't have such a script.
> >
> > Where can I sign up for an account on your server?
> >
> > --
> > Gunnar Hjalmarsson
> > Email: http://www.gunnar.cc/cgi-bin/contact.pl

>
> That's a shame ;(
> Sorry but u can't sign up for it (yet ) it's for an private collage
> network
> btw.. sorry for the crappy english but i hope you all understand what i am
> trying to write here
>
>


Btw this is what i made up so far
#!/usr/bin/perl

use HTTP::Request;
use HTTP::Response;
use LWP::UserAgent;

$PrintDebug = 1; # Print debugging information
$baseURL = "Url to asp file with data";
$ip = &get_ip();

sub Debug(@){
$strDebug = shift;
if ($PrintDebug == 1) { print("$strDebug\n"); }
}

sub get_ip {
my ($myip, @iparr) = (undef, []);
$_ = `ifconfig`;
@iparr = /inet addr\d+\.\d+\.\d+\.\d+)/ig;
$myip = $iparr[0];
return $myip;
}

# Aanspreken hosting.asp file via http request
sub ExecHttpReq(@)
{
my $URL = shift;
my $ua = new LWP::UserAgent;
$ua->agent( "Routit Backend");
die "No useragent" unless defined($ua);
$req = new HTTP::Request('GET',$URL);
return $ua->request($req);
}

$response = ExecHttpReq("$baseURL/hosting.asp");

if( !$response->is_success ){
print $response->status_line;
print " FAILED\n";
exit 1;
}

# splitten van hosting.asp file voor het gebruiken van de data
@lines = split /\n/, $response->content;
for( $i=0; $i<= $#lines; $i++ ){
($ID, $ProductCode, $DealerKlantID,
$Naam, $DealerID, $Bedrijf,
$Username, $Password, $Domainname,
$ASP, $PHP, $Stats,
$Tag, $server) = split /\t/, $lines[$i];
$status = 0; #OK, account created

# Kijken of de hosting niet voor windows is
chomp $PHP;
chomp $Tag;
if($PHP =~ /true/) {
$status = createuser($Username, $Password);
$status = createvirtualhost();
# updatestatus($ID, $status);
}
# Kijken of dat er stats nodig zijn
if($Stats=~ /true/) {
$status = awstats();
}
if($Tag =~ /2/) {
$status = deleteall();
}
if($Tag=~ /3/){
$status = deletestats();
}

# Sub maken van user
sub createuser(@) {
Debug ("Making User");
chomp $Username;
Debug("Setting Password");
chomp $Password;
system("adduser -g webusers -d /var/www/$Domainname $Username");
system("echo \"$Password\" | /usr/bin/passwd --stdin $Username");
Debug("User added...");
chmod (0750, "/var/www/$Domainname");
Debug("Setting permissions...");
return 0; # account create
}

# Sub hosting status
sub updatestatus(@) {
ExecHttpReq("$baseURL/hosting.asp?ID=$ID#Status=$status");
}

# Sub voor het maken van Virtualhosts
sub createvirtualhost(@) {
Debug("setting domainname");
Debug( "mkdir $Domainname");
print("mkdir() ", mkdir("/etc/httpd/conf/virtualhosts/$Bedrijf",
0750),"\n");
print "making apache virtualhost dir\n";
open(APACHECONF,
">/etc/httpd/conf/virtualhosts/$Bedrijf/$Domainname.conf");
$strCONF = "<VirtualHost $ip>\n";
$strCONF .= "\tDocumentRoot /var/www/$Domainname\n";
$strCONF .= "\tServerName $Domainname\n";
$strCONF .= "\tServerAlias www.$Domainname\n";
$strCONF .= "\tServerAdmin webmaster\@$Domainname\n";
$strCONF .= "\tErrorLog logs/$Domainname.error.log \n";
$strCONF .= "\tCustomLog /var/log/httpd/$Domainname.log combined\n";
$strCONF .= "</VirtualHost>\n";
print APACHECONF $strCONF;
print "helemaal klaar !\n";
close(APACHECONF);
return 0; # Virtual host file created
}

print "Restarting Apache deamon\n";
system("killall -HUP httpd");
print "Klaar.\n";

# Sub voor het maken van de AWStats
sub awstats(@) {
Debug ("Making the dir and setting the awstats settings");
print("mkdir() ", mkdir("/var/www/$Domainname/stats", 0750),"\n");
print("chmod() ", chmod(".R /var/www/$Domainname/stats/", 0750),"\n");
system("cp -R /sys/scripts/awstats/icon/ /var/www/$Domainname/stats/");
system("chown -R root:webusers /var/www/$Domainname/stats");

# Het openen en editten van de template van awstats..

$domain = "$Domainname";
open(TEMPLATE, "</sys/scripts/awstats/awstats.conf");
open(CONFIG, "> /etc/awstats/awstats.$Domainname.conf");
@TEMPLATE=<TEMPLATE>;
for (@TEMPLATE) {
s/<DOMAIN>/$Domainname/g;
}

print CONFIG "@TEMPLATE\n";
close TEMPLATE;
close CONFIG;

return 0; # awstats done !


}

sub deleteall(@) {
Debug ("Setting up for all delete");
print ("rm() ", rm("/var/www/$Domainname/stats"),"\n"); # lets see if this
works
print ("rm() ", rm("/var/www/$Domainname"),"\n"); # lets see if this works
print ("rm() ", rm("/etc/httpd/conf/virtualhosts/$Bedrijf"),"\n");
# print ("rm() ", rm("/etc/awstats/awstats.$Domainname.conf"),"\n);

}
#sub deletestats(@) {
}


 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      06-24-2004
Henk <(E-Mail Removed)> wrote:

> Btw this is what i made up so far



You forgot these 2 lines:

use warnings;
use strict;


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      06-26-2004
Henk wrote:
> i don't know how to check if the username already exists in linux


linux% perl -le 'print join ":",getpwnam("jms")'
jms:103:103:::Joe Smith:/home/jms:/bin/tcsh
linux% perl -le 'print join ":",getpwnam("invalid")'

linux% perldoc -f getpwnam

-Joe
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a Python script from crontab Astley Le Jasper Python 19 12-05-2008 04:27 AM
Re: script won't run using cron.d or crontab Robert Bossy Python 0 03-21-2008 08:01 AM
still get a <defunct> using a python script in the crontab martijn@gamecreators.nl Python 2 09-19-2007 03:02 PM
appended crontab entries with py script rbt Python 3 09-20-2005 02:50 PM
Perl Script Not Running From Crontab. Matt Cluver Perl Misc 3 04-17-2004 12:23 PM



Advertisments