Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-28-2009, 12:24 AM   #1
LQ Newbie
Registered: May 2009
Posts: 2

Rep: Reputation: 0
first cgi script not returning anything on browser

Hi CGI gurus,
pls tell me what iam doing wrong. THis is my first cgi script. I want to remote ssh to a unix server and get its 'df -k " info on the webpage

echo "Content-type: text/html"
echo ""
echo "<html><head><title>Bash as CGI"
echo "</title></head><body>"

echo "<h1>Memory Info</h1>"
echo "<pre> $(ssh -q uname@remoteIP df -k) </pre>"
echo "</body></html>"

It works fine on linux serevr iam running ie it displays df -k info of remote IP but on web page nothing shows except header "Memory Info"
Old 05-28-2009, 01:49 AM   #2
Registered: May 2001
Posts: 29,359
Blog Entries: 55

Rep: Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546
The main difference in running this and the webserver is the unprivileged user account. Your account has other access rights, a tty and is able to authenticate interactively, the webserver does not as it's not used for that kind of thing. So as far as I can see it's not the CGI itself but the retrieval method. Ofcourse you could set up your webserver with for it and use a remote ssh account that is limited to running a script but that's not that scalable and requires more overhead than is strictly necessary (IMHO). Reinventing the wheel depends on if this is just a testbed exercise in scripting or what other details you want to get from that or other systems later on and if you got admin access to those. For instance having SNMP running would make things easier (as in efficient, scalable) or say Nagios if you're about to handle stats on more systems. If you have admin access on the remote machine and Xinetd is running and you don't want SNMP or Nagios then you could try this on the system to monitor:
# default: off
# description: /etc/xinet.d/xinetd_sysstats_df: output of 'df'. 
service xinetd_sysstats_df
        disable         = no
        type            = UNLISTED
        protocol        = tcp
        port            = 30002
        socket_type     = stream
        wait            = no
        user            = root
        log_on_failure  += HOST 
        server          = /bin/df
        server_args     = -k
        # Activate ctrls wrt your used subnet:
        # only_from       =
Then if instead of ssh you use curl, wget, nc, telnet or even Bash on the monitoring station to fetch "http://serveraddress:30002" you avoid most complications.

Last edited by unSpawn; 05-28-2009 at 01:51 AM. Reason: //more *is* more..


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
calling CGI script in CGI script ravi_chobey Programming 3 03-19-2009 12:36 PM
PHP script returning a 255 errorcode ibnpaul Linux - Software 0 11-06-2007 10:26 PM
cgi via web browser censanian Linux - Server 1 07-13-2007 03:51 PM
Can not access cgi-bin from browser. Spreegem Linux - Software 6 11-07-2005 07:22 PM
Apache CGI Problem : Browser not running script Zaknafien Linux - Software 3 12-31-2003 01:16 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:11 AM.

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