LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 05-28-2009, 12:24 AM   #1
linux_cv
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


#!/bin/bash
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
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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:
Code:
# 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       = 127.0.0.1 10.0.0.0/24
}
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..
 
  


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
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:49 PM.

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