Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7722583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:13:03+00:00 2026-06-01T04:13:03+00:00

Ok guys, I know this is pretty a rare case but I really would

  • 0

Ok guys, I know this is pretty a rare case but I really would appreciate your wise comments on this.

I am developing a monitoring/operational web gui using CGI (Perl/SSH) to monitor more than 20 severs. Most of the work is done, I have prepared the shell scripts and we are automating most of the stuff there. Anyways, we are persuaded to provide a front-end for the monitoring and automation stuff we did.

Long story short, I am using one of the server as the main gateway to run the CGIs.
What is my plan, on this server, I use Perl CGI to run shell scripts by using for example qx() function and put the output in a file. the shell script will connect to other servers and run the command. the problem is while I run the cgi or shell script in the SSH it works fine and it prints the output but when I call the cgi through web it only returns until the shell output of CGI server (the one that Im connecting to is not there while with SSH its working fine).

here is the CGI code:

#!/usr/bin/perl -w
use strict;
use CGI;
use Shell;

my $query = new CGI;
print $query->header(-charset=>'utf-8');

 my $value=qx(sh dspace91.sh > space.txt);
 open(FILE, '<space.txt') or die "Can't read file [$!]\n";

 while (<FILE>){
 $document = $document .  $_;
 }

 close FILE;
 my $gdate=qx(date);

 print  "<div id='black' style='color:white'><pre>$document</pre>Information generated on <font color='#00CC00'>$gdate</font></div>";

and here is the shell script code (dspace91.sh file)

#!/bin/bash

expect -c 'spawn ssh -q username@serverIP "df -h"; expect password ; send "password\n" ; interact; ';

exit;

What I assume is the problem is working with I/O environment variables. something to do with STDOUT. not sure though!

this is the output when I run the CGI through SSH:

spawn ssh -q username@serverIP df -h
username@serverIP's password:
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              20G  7.1G   12G  39% /
/dev/sda7              90G   25G   61G  29% /iwa
/dev/sda6             4.9G  1.3G  3.4G  28% /oracle
/dev/sda3              10G  595M  8.9G   7% /var
/dev/sda1              99M   45M   49M  48% /boot
tmpfs                  16G     0   16G   0% /dev/shm
drst002:/logs         400G  274G  127G  69% /backup-logs
drst002:/unix         7.0T  5.2T  1.9T  74% /unix

this is the output when I run it through the web gui:

spawn ssh -q username@serverIP df -h
username@serverIP's password: 

Information generated on Tue Apr 3 02:21:47 IRDT 2012

Any ideas folks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:13:05+00:00Added an answer on June 1, 2026 at 4:13 am

    Some ideas:

    • Use ssh public key authentication and eliminate the need to use expect altogether.

      expect is a nasty hack that never proves reliable enough.

    • try:

      expect -c '...' 2>&1

    • also, but I don’t think that’s the case, CGIs usually run into trouble because they run as a different user than the one the developer is testing on the command line with. Always check if that could be affecting your setup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

guys I know this question is very basic but I've met in few publications
Guys I know this question is silly but just to make sure: Having in
I know that this is a simple question for PHP guys but I don't
I would like to know what guys are using to make diagram of your
Hey guys I know this is an old issue but I am wondering if
Again, I'm here looking for your wisdom, in this case, I need to learn
It seems pretty common to want to let your javascript know a particular dom
So, this may seem very elementary for you guys but I am officially stumped.
I would love to brainstorm with you guys on how to program this game
I'm sorry if this comes through as a noob question, but I'm really stuck

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.