[wellylug] Issues with a perl script
scott
scott at slackisland.org
Thu Oct 26 14:48:41 NZDT 2006
Hi,
It seems that passing the commands is not working correctly in this
script- I removed the modifiers and played around with it a bit- this
seemed to work, but it doesnt have the directory permissions as
required...
#!/usr/bin/perl -w
my $line;
mkdir ("/home/scott/profiles");
open(USERS, "/usr/bin/getent passwd|");
while ($line = <USERS>) {
my ($name, $password, $uid, $gid) = split(/\:/, $line);
if ($name !~ /^[\w\ \-\+]+$/) {
next;
}
if (-e "/profiles/$name") {
next;
}
if (($uid =~ /^\d+$/) && ($gid =~ /^\d+$/))
{
mkdir("/home/scott/profiles/$name");
chown($uid, $gid, "/home/scott/profiles/$name");
}
}
close(USERS);
Cheers,
Scott VanDusen
On Thu, 2006-10-26 at 10:28 +1300, Geraint M. Jones wrote:
> I have the following script from a book (about windows & linux
> intergration)
>
> #!/usr/bin/perl -w
> my $line;
> mkdir(/profiles/, 0755);
> open(USERS, "/usr/bin/getent passwd|");
> while ($line = <USERS>) {
> my ($name, $password, $uid, $gid) = split(/\:/, $line);
> if ($name !~ /^[\w\ \-\+]+$/) {
> next;
> }
> if (-e "/profiles/$name") {
> next;
> }
> if (($uid =~ /^\d+$/) && ($gid =~ /^\d+$/))
> {
> mkdir("/profiles/$name", 0700);
> chown($uid, $gid, /profiles/$name);
> }
> }
> close(USERS);
>
> however it fails with the following errors
>
> [root at ella ~]# ./makeprofile.pl
> Scalar found where operator expected at ./makeprofile.pl line 16, near
> "/profiles/$name"
> (Missing operator before $name?)
> syntax error at ./makeprofile.pl line 16, near "/profiles/$name"
> Execution of ./makeprofile.pl aborted due to compilation errors.
>
> Unfortunately I know no perl - anyone see any glaring problems with it ?
>
> G
>
>
> --
> This e-mail and any attached files are confidential and may be legally privileged. If you are not the addressee, any disclosure, reproduction, copying, distribution, or other dissemination or use of this communication is strictly prohibited. If you have received this transmission in error please notify the sender immediately and then delete this mail.
> E-mail transmission cannot be guaranteed to be secure or error free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission or changes to transmitted date not specifically approved by the sender.
> If this e-mail or attached files contain information which do not relate to our professional activity we do not accept liability for such information.
> This email has been scanned for all currently known viruses by Proxmox v1.5
>
>
More information about the wellylug
mailing list