LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2002, 01:18 PM   #1
amartinez
LQ Newbie
 
Registered: Sep 2002
Posts: 4

Rep: Reputation: 0
Smile CGI and BASH. Can anyone helpme whit this code ?


My cgi checks /mqueue , but i can't make awk prints something on the browser.
If i put some command like : df, mount, free, etc i see the result in the browser, but when i run this script out of the browser (in the shell) it works fine but in the browser it doesn't.



#!/bin/bash

echo Content-type: text/html
echo
echo
echo "<meta http-equiv="refresh" content="8">"
echo "<html><head><h1 align=center>CONTROL DE SERVICIOS</h1></head>"
echo "<h3><pre>"
for i in $(ls var/spool/correo/mqueue/qf*)
do
cat $i | awk ' BEGIN{status=""}
/^A/ { print "De: "substr($0,2) }
/^RPFD:/ { print "Para: "substr($0,6) }
/^M/ { print "Estado: "substr($0,2) }
END {print "*----------*"}'
done
ls /var/spool/correo/mqueue
echo "</h3></pre></html>"
 
Old 09-30-2002, 02:10 PM   #2
startup
LQ Newbie
 
Registered: Sep 2002
Posts: 2

Rep: Reputation: 0
Probably because the PATH variable isn't set up in the apache
session, so your script can't find cat, awk, etc.

Either hard-code the paths (eg. /usr/bin/awk) or include a path setup at the top of your script similar to ...

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
 
Old 10-01-2002, 01:10 PM   #3
amartinez
LQ Newbie
 
Registered: Sep 2002
Posts: 4

Original Poster
Rep: Reputation: 0
Cgi and Bash

if have added the next in httpd.conf

<IfModule mod_env.c>
SetEnv PATH /usr/sbin
</IfModule>


I still can't make my cgi work.

thanks.
 
Old 10-06-2002, 11:06 PM   #4
kervin
Member
 
Registered: Jan 2002
Location: Melbourne, FL.
Distribution: redhat
Posts: 168

Rep: Reputation: 31
using shell with cgi is probably not the safest thing to do.

Why don't you use PHP or PERL?
 
Old 10-07-2002, 07:15 AM   #5
amartinez
LQ Newbie
 
Registered: Sep 2002
Posts: 4

Original Poster
Rep: Reputation: 0
CGI and BASH

OK, I'll try

Thanks
 
Old 10-09-2002, 03:15 AM   #6
kwigibo
Member
 
Registered: Apr 2002
Posts: 53

Rep: Reputation: 15
C/C++ would also be a better alternative to bash or perl.
 
Old 10-09-2002, 08:43 AM   #7
kervin
Member
 
Registered: Jan 2002
Location: Melbourne, FL.
Distribution: redhat
Posts: 168

Rep: Reputation: 31
Quote:
Originally posted by kwigibo
C/C++ would also be a better alternative to bash or perl.
I am going to have to disagree. I would choose PERL over C/C++ because...

(i)No memory management necessary. - With C++ your program has to be debugged for NULL pointer references etc.
(ii)It is better to use a language that has a apache module instead of CGI - Apache modules eg. mod_perl, mod_php are *much* faster than CGI

Over all writing a script would be much quicker than writting/debugging a C/C++ program, plus it would be faster in the case of PHP/PERL on apache.

Between PHP and PERL and also say go with PHP. You'll get more snips of web code to do what you want, in case you need help I think.
 
Old 10-09-2002, 09:11 AM   #8
amartinez
LQ Newbie
 
Registered: Sep 2002
Posts: 4

Original Poster
Rep: Reputation: 0
Thumbs up CGI and BASH

Thanks.
 
Old 10-09-2002, 08:59 PM   #9
kwigibo
Member
 
Registered: Apr 2002
Posts: 53

Rep: Reputation: 15
I'd go with PHP too out of the lot but my second choice would be C/C++, then perl.
 
Old 10-11-2002, 03:31 PM   #10
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
Quote:
Originally posted by kwigibo
I'd go with PHP too out of the lot but my second choice would be C/C++, then perl.
No offense meant, but how much CGI scripting have you done? With PHP? Perl? C? C++? how long have you been coding with each?

I've been coding in C for 10+ years, and perl for 2 years, I know php enough to get by... I love C, I always have... but I think I'd rather someone shot me in the foot than make me write a CGI in it.

Debugging a C CGI is not pretty. Development time in C is doubled (and sometimes more) over any scripting language such as perl or a browser based language, such as php or javascript.

Don't misunderstand me, C is always going to be my favorite, but every language has it's place. C and C++ can most certainly be used for CGI's and can in cases outperform scripts, but considering development time, I'd rather use perl. Now, if I had taken the time to develop an extensive library for handling alot of the memory management stuff and taking care of alot of the GC and such, I'd maybe reconsider... but why do that when php and perl make scripting a snap?

Of course, you may have some tools or experience I don't, which leads to your decision.. my personal opinion is simply that C and CGI don't mix well.



amartinez:

Does calling awk with a full path help, as startup suggested? If not, what does the error log say? It should provide you with details to determine what's going on..

My first thought was that awk was not printing to stdout.. I'm not sure what it defaults to, but you could probably force it to dump everything to stdout... just an idea.

TLD
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
stripping of bash code? Lindows45 Linux - Newbie 2 03-01-2004 07:51 AM
where is the bash source code?... gearoid Programming 5 11-25-2003 04:24 AM
perl newbie. hangman.cgi script displaying strangely (additional code) on the web. WorldBuilder Programming 4 11-21-2003 07:09 AM
Bug in c code calling bash code Linh Programming 11 08-12-2003 04:27 AM
http://www.burstnet.com/cgi-bin/ads/ad7954a.cgi/3980/RETURN-CODE rverlander LQ Suggestions & Feedback 1 06-07-2002 07:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration