#!/usr/bin/perl use strict; $|++; use CGI qw(:all); # import shortcuts use Fcntl qw(:flock); # imports LOCK_EX, LOCK_SH, LOCK_NB use CGI::Carp qw(warningsToBrowser fatalsToBrowser); # For Debugging use Net::SSH::Perl; use CGI qw(:all delete_all escapeHTML); print header; my ($TITLE,$DeploySvr,$KIT,$ssh,$UNM,$Pass,$stdout,$stderr,$exit,$cmd, +$session,$cache,$data,$pid,); if (my $session = param('session')) { # returning to pick up session data $cache = get_cache_handle(); $data = $cache->get($session); unless ($data and ref $data eq "ARRAY") { # something is wrong exit 0; } print start_html(-title => "Logging...", ($data->[0] ? () : (-head => ["<meta http-equiv=refresh content=5 +>"]))); print h1("Logging..."); print pre(escapeHTML($data->[1])); print p(i("... continuing ...")) unless $data- +>[0]; print end_html; } else {ExecuteProcess();} sub ExecuteProcess { $session = get_session_id(); $cache = get_cache_handle(); $cache->set($session, [0, ""]); # no data yet $DeploySvr=param('DrpServer'); $KIT=param('TxtKit'); $UNM=param('username'); $Pass=param('password'); if ($pid = fork) { # parent does delete_all(); # clear parameters param('session', $session); print redirect(self_url()); } elsif (defined $pid) { # child does close STDOUT; # so parent can go o +n $ssh = Net::SSH::Perl->new('113.128.122.27'); $ssh->login($UNM, $Pass); $cmd="ls -l"; my($stdout, $stderr, $exit) = $ssh->cmd($cmd); my $buf = ""; while ($stdout) { $buf .= $_; $cache->set($session, [0, $buf +]); } $cache->set($session, [1, $buf]); exit 0; } else { die "Cannot fork: $!"; } } sub get_cache_handle { require Cache::FileCache; Cache::FileCache->new ({ namespace => 'LogOutput', username => 'nobody', default_expires_in => '30 minutes', auto_purge_interval => '4 hours', }) } sub get_session_id { require Digest::MD5; Digest::MD5::md5_hex(Digest::MD5::md5_hex(time().{}.rand().$$)); }
In the above code , i tried to fork the process. This CGI gets information from another HTML page which posts info into this.basically it connects to a remote box using SSH module using the username and password provided from the HTML page and lists the output in the web page. On execution , it fork's the process , but unable to display the messages from the forked command.Also, the web page seems like waiting, so I think that Apache has not received the end signal. Please review and let me know

In reply to Re^2: Asynchronous Processing a command execution by Alfaromeo
in thread Asynchronous Processing a command execution by Alfaromeo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.