in reply to Re: Need a way to print script output to web page?
in thread Need a way to print script output to web page?

(See update below...)

I had some semi-serious issues with Webalizer. I'm using OS X, and it came with a nifty Perl install script. But it hosed my httpd.conf (it did, at least, make a backup). Check out the offending section (note that $t is input from a diamond operator):

if ($t =~ /^y/) { `cp /etc/httpd/httpd.conf /etc/httpd/httpd.conf.save`; $orig = 'CustomLog "\/private\/var\/log\/httpd\/access_log" common +'; $new = 'CustomLog "\/private\/var\/log\/httpd\/access_log" combine +d'; print "Modifying apache configuration..."; `/usr/bin/sed -e 's/$orig/\#$orig/' -e 's/\#$new/$new/' /etc/httpd +/httpd.conf > /etc/httpd/httpd.conf`; print " done. \n\nOriginal saved to /etc/httpd/httpd.conf.save\n\ +n"; print "Apache needs to be restarted for this to take effect, would + you like to do this now? (y/n) "; $a = <>; if ($a =~ /^y/) { print "Restarting apache..."; print " done\n\n"; } }
Note a few things. This script needs to be run as root (I did, via sudo). Backticks in void context, then a sed call (sed? From within Perl?!). I believe the sed call is what zeroed out my httpd.conf. Then, the part that I'm just fuming about. "Would you like to restart Apache?" I say yes. Script does nothing. "OK!"

It took me a little over a half hour to debug this. I didn't see any problems because I didn't have to reboot my machine until tonight (I originally installed Webalizer yesterday morning). And I only had to reboot tonight because I installed some other random program -- so I thought that the other program was the culprit (but it has nothing to do with Apache, which is why I was stumped).

All in all I really like the reports from Webalizer. But be warned if you install it with the OS X script. I'll be contacting the author with this information after this...

Update: I don't recall exactly which version of Webalizer had this malfunctioning script, but the latest seems to have addressed the problem. The script still has backticks in void context (so no error checking to see if the command failed) but at least it does actually perform the 'apachectl restart' when you tell it to. Just in case you were curious.