help-cfengine
[Top][All Lists]
Advanced

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

Re: ExecResult and pipes?


From: Knut Auvor Grythe
Subject: Re: ExecResult and pipes?
Date: Fri, 24 Jun 2005 00:03:17 +0200
User-agent: Mutt/1.5.6i

On Thu, Jun 23, 2005 at 02:15:06PM -0700, Steve Foley wrote:
> Im trying to understand why the following code (run under 2.1.14):
> 
>     modules_ver = ( ExecResult(/bin/ls -1 /lib/modules |/usr/bin/tail  -1 ) )
>     modules_dir = ( "/lib/modules/$(modules_ver)" )

ExecResult probably doesn't spawn a shell at all, but just runs the
command. The pipe isn't evaluated by a shell, and is thus regarded as
plain text. (You'd get the same effect if you escaped a pipe in the
shell.)

There is probably a fancy option to turn using the shell on, but I do
not know it. I guess I'll just give you the hack and let others do the
clever stuff later if they feel like it ;-)

     modules_ver = ( ExecResult(/bin/sh -c "/bin/ls -1 /lib/modules | 
/usr/bin/tail -1") )
     modules_dir = ( "/lib/modules/$(modules_ver)" )

But are you sure this is what you really want? Because that would
probably give you a pretty weird result. For instance, if you have the
kernels 2.6.8, 2.6.9 and 2.6.11 installed, that command would pick
2.6.9, since ls sorts the files alphabetically by default. 

If you want the newest directory, "ls -1rt | tail -1" (or equivalently:
"ls -1t | head -1") would probably be closer to what you want, assuming
you want the modules directory last modified. But the last modified
directory is not necessarily your running kernel (you might not have
rebooted after your last kernel upgrade, for instance). If you want your
currently running kernel, simply use "/bin/uname -r".


-- 
Knut Auvor Grythe
ITEA Systemdrift




reply via email to

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