[wellylug] Issues with a perl script

Donovan Jones hta.lists at gmail.com
Thu Oct 26 19:19:06 NZDT 2006


Thats a pretty ugly script, whats it actually trying to do?

first thing wrong is the quoting it should be '/profiles/' on the
mkdir(/profiles/, 0755); line (do you realy want a profiles dir in /?)

and in chown($uid, $gid, /profiles/$name); it should be "/profiles/$name"

a slightly better way  using perls builtin pwent stuff might be like this:

start---------------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;

my $profile_dir = '/profiles/'; # do you realy want this? need to be root
mkdir($profile_dir, 0755) or die "cannot make dir $profile_dir: $!";

setpwent();
while (my ($name, $uid, $gid) = (getpwent())[0, 2, 3]) {
  next unless $name =~ /^[\w\ \-\+]+$/;
  my $name_dir = "$profile_dir/$name";
  next if -e $name_dir;
  mkdir ($name_dir, 0700) or die "cannot make dir $name_dir: $!";
  chown ($uid, $gid, $name_dir) or warn "need to be root!: $!";
}
endpwent();
---------------------------------------------------------end

but if you only want real users then add a

next if $uid < 1000;

Don Jones
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wellylug.org.nz/pipermail/wellylug/attachments/20061026/f1b6096a/attachment.htm 


More information about the wellylug mailing list