Exec and Pipes

MiniMe
Posts: 210
Joined: Thu Mar 15, 2001 4:30 pm

Exec and Pipes

Post by MiniMe »

I am trying to get an exec to run a unix command that contains pipes but for some reason it keeps failing.. it looks like this.

<exec NOBR cat /db/logs/access_log |grep -i sub |wc -l>
</exec>
<loop $ret>
$ret
</loop>

I want $ret to equal the numeric value generated by wc -l. Whats the trick?
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

Exec and Pipes

Post by Kai »

<EXEC> is not system(): it does not run the shell, for security and speed reasons; therefore it cannot do wildcard expansion or pipes.

The command you're doing can be done faster in Vortex anyway:

<$n = 0>
<readln row /db/logs/access_log>
<rex MAX=1 "sub" $ret></rex>
<if $loop gt 0><sum "%d" $n 1><$n = $ret></if>
</readln>
`sub' occurs in $n lines in access_log

See also the REV option to <readln>, at http://www.thunderstone.com/site/vortexman/node45.html. See also <REX> at http://www.thunderstone.com/site/vortexman/node105.html.
aitchon
Posts: 119
Joined: Mon Jan 22, 2007 10:30 am

Exec and Pipes

Post by aitchon »

How would I run an exec with the following command that does use pipes?

ip route show | grep default | awk '{ print $3}'
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Exec and Pipes

Post by mark »

<exec "/bin/sh" "-c" "ip route show | grep default | awk '{ print $$3}'"></exec>
<$gateway=$ret>

Or better, use vortex:
<exec ip route show></exec>
<rex ">>default via \P=[\digit.]+" $ret>
<$gateway=$ret>