help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: modules bug with pre-scanning for a user


From: Mark . Burgess
Subject: Re: modules bug with pre-scanning for a user
Date: Tue, 12 Jun 2001 13:14:09 +0200 (MET DST)

On 11 Jun, Ted Zlatanov wrote:
> I want cfengine to quietly define a class if a user exists on the
> system.
> 
> My first try was:
> 
> groups:
>  JoeFound = ( "/bin/grep joe /etc/passwd" )
> 
> commands:
>  JoeFound::
>   "/bin/echo found Joe"
> 
> Which works, but always prints out the passwd line for Joe when
> cfengine runs.  grep -c was a little better (prints out 1 or 0), but
> still annoying.
> 
> I then wrote a plugin "grepper" module, which basically should do a
> grep but without printing anything out:
> 
> ----
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my $pattern = shift @ARGV;
> my $file    = shift @ARGV;
> my $class   = shift @ARGV or die "invoke as '$0 PATTERN FILE CLASS'";
> 
> open FILE, "<$file" or die "Couldn't open file $file: $!";
> 
> while (<FILE>)
> {
>  print "+$class" if $_ =~ /$pattern/;
> }
> ----
> 
> And I invoke it as:
> 
> control::
>   actionsequence = ( "module:grepper joe /etc/passwd JoeFound" )
> 
> All the settings are correct; cfengine -v shows that JoeFound gets
> defined when joe is in the /etc/passwd file and doesn't get defined
> otherwise.
> 
> Now, the problem.  The following files: section
> 
> files:
>  JoeFound::
>   /home/joe mode=0777 owner=joe recurse=inf action=fixdirs
> 
> generates an error whether Joe is or isn't in the /etc/passwd file,
> whether the JoeFound class is or isn't defined; complaining
> 
> "Unknown user joe
> ice:cfengine.conf:78: Warning: User is not known in this passwd domain"
> 
> Which I know, so I don't need the warning.  As a matter of fact, the
> whole exercise was in order to eliminate that warning.  My guess is
> that the user name is checked before the module is run.
> 
> JoeFound is in the AddInstallable list of classes.  cfengine version
> 1.6.2.
> 
> I could fix this by using the grepper module by name as a script in
> the classes section, of course.  I would like to get modules and
> dynamically generated classes working for my own benefit, however, and
> I would like to know if this is a bug or expected behavior.
> 
> Thanks
> Ted


This is expected behaviour if the JoeFound class is defined. There have
been bugs related to class definition, but I'm not sure what is the
problem in your case. My tip would be to use your orginal idea, but like
this to remove the output

groups:
 JoeFound = ( "/bin/grep joe /etc/passwd >/dev/null  2>&1" )

best
Mark

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Work: +47 22453272            Email:  Mark.Burgess@iu.hio.no
Fax : +47 22453205            WWW  :  http://www.iu.hio.no/~mark
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





reply via email to

[Prev in Thread] Current Thread [Next in Thread]