Forum OpenACS Q&A: exec problem

Collapse
Posted by Ola Hansson on
I'm experimenting with Webalizer and writing a scheduled procedure that will build a report on a regular basis, based on the data in the rolled access log.

"exec" doesn't want to do the FOR LOOP that I want it to do, though.

eval "exec -keepnewline {for i in $log.*; do
$command $params $i
done}"
This is the error I get:
couldn't execute "for i in 
/usr/local/aolserver/log/infogettable-dev/infogettable-dev.log.*; 
do
/usr/local/bin/webalizer  -p  -o 
/web/infogettable-dev/www/webalizer  -D": no such file or 
directory
What am I doing wrong?
Collapse
2: Response to exec problem (response to 1)
Posted by Don Baccus on
"exec" just does a system exec() call, in other words it runs the given program with the given list of arguments.  It doesn't run a shell.  Things like "for" are shell commands.  You may be a bit confused because the shells you're used to try to run commands as a program if they're not recognized as part of the shell's syntax.

So ... what you need to do is to exec a shell of your choice (bash, sh, csh, etc) and pass the proper arguments to it.

Collapse
3: Response to exec problem (response to 1)
Posted by Tom Jackson on

Or write your script into a file and exec that file.

Collapse
4: Response to exec problem (response to 1)
Posted by Don Baccus on
That works too - remember to put the #!/bin/sh in there at the top, though!
Collapse
5: Response to exec problem (response to 1)
Posted by David Walker on
set myresponse [exec -keepnewline bash -c {for i in $log.*; do  
$command $params $i  
done}]


Or, assuming you want $i to be related to "for i" and $log,$command, and $params to be your tcl variables
  
set myresponse [exec -keepnewline bash -c "for i in $log.*; do  
$command $params $i  
done"]  
Collapse
6: Response to exec problem (response to 1)
Posted by Ola Hansson on
Thanks for your help.

I have put the procedures here in case someone else wants to use them.

webazolver runs separately to create the DNS cache file. webalizer then uses that file to show names instead of IPs.