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: Sharif Nassar
Subject: Re: modules bug with pre-scanning for a user
Date: Fri, 15 Jun 2001 16:13:23 -0700 (PDT)

how about grep -q ?

 groups:
  JoeFound = ( "/bin/grep -q joe /etc/passwd" )

Of course, this won't work with "traditional" grep as noted in the man
page for GNU grep:

=quote
     -q, --quiet, --silent
              Quiet;  suppress  normal output.  The scanning will
              stop on the first match.  Also see the -s or  --no-
              messages option below.

     -s, --no-messages
              Suppress  error  messages  about   nonexistent   or
              unreadable  files.   Portability  note:  unlike GNU
              grep, traditional grep did not conform to  POSIX.2,
              because traditional grep lacked a -q option and its
              -s option behaved like GNU grep's -q option.  Shell
              scripts intended to be portable to traditional grep
              should avoid both -q and  -s  and  should  redirect
              output to /dev/null instead.

=endquote

Of course, this suggests that you could use -s for a traditional grep.
Still not too portable, if you've got lots of operating systems (or
versions of grep).  You could do what I have been known to do:  write a
wrapper script for cfengine call that passes the right args to grep.

-sharif

On 11 Jun 2001, 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
>
>
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@gnu.org
> http://mail.gnu.org/mailman/listinfo/help-cfengine
>




reply via email to

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