khangol has asked for the wisdom of the Perl Monks concerning the following question:

Okay forgive me if I have bad formatting as it's only my second post... What I'm trying to do: When I click a link, I want it to run a batch file to install a program on a server, and return a result upon installation failure or success. The Problem: I first wrote this script to be executed through the command line, so when I had to make some changes to make it work through a web browser. The batch file takes about five minutes to complete, so I had to prevent the browser to time out. Here's my code:
#!perl -w use CGI; $c = new CGI(); print $c->header(); $| = 1; ### set up an alarm $timeout = 7*60; # apache normally times out after 5 min print "<!--\n"; # hide output $SIG{ALRM} = sub{ print ".\n"; alarm($timeout); }; # the timeout will send something to the browser every # now and then to keep it from timing out alarm($timeout); print "Installing Dell Open Manage"; &install_open_manage(); alarm(0); print "-->\n"; # don't need to hide output anymore print $result; <---- do other stuff here ----> exit(); sub install_open_manage { $host = "hostA"; print "\n$count: Checking for local RAC configuration.<br>"; sleep(1); $result = `psexec \\\\$host -u location\\admin -p password \\\ +\host01\\OpenManage\\setup_sibar.bat 2>&1`; return $result; }
The script runs, and the program is installed, but the results and the stuff after it is not printed.
***EDIT Still no luck. I added  start before the psexec and redirected the output to a text file, however nothing gets written to the file. One thing i noticed is that if I do something other than an install in the install_open_manage subroutine (such as a sleep(100) and a 'dir' command) my script works fine.

Replies are listed 'Best First'.
Re: Installing a program on a remote server through a web browser.
by unlinker (Monk) on Jan 03, 2011 at 16:48 UTC

    If the install script is just one of the many things that your CGI program does, you could try forking your CGI process. A nice description (with code) of how this can be achieved is by Randall Schwartz in one of his Perl columns and is archived here.

    However if you are planning to run several installs, a good option would be to hive off your install action to a message queue where a worker script could take over the job of running your install script. There are several message queues that work with Perl. See TheSchwartz, Gearman and Beanstalk for message queues that play well with Perl. You can then implement the Cache::Cache trick in Randall's script to track the worker's (install) progress

    Hope this helps

      this CGI program does a few things, but the install is really the only intensive part. The suggestions you gave are beyond my Perl capabilities at this time, but thanks for your input!
Re: Installing a program on a remote server through a web browser.
by anonymized user 468275 (Curate) on Jan 03, 2011 at 16:51 UTC
    How about detaching the spawned process by preceding the "psexec" command with "nohup ". You also need to direct output to a file, not just redirect standard error to standard out, otherwise it defaults to nohup.out.

    update: and of course bracket the multiple shell commands to collectively nohup them -- oh and you don't need '\' to delimit them, which seems to have caused some fumbling around -- ";" will do.

    One world, one people

      I am researching nohup (and how to do it) but if you have time, an explanation would be great. I also don't understand what you mean about the delimit part. are you talking about the
      $result =`psexec \\\\$host -u carynt\\rdcadmin -p 2backup! $racadm get +sysinfo 2>&1`;
      if I remove the extra '\' it doesn't work. thanks!
      nohup appears to be a unix command. I am running this script on a windows server (psexec is also a windows program). any way to do this on windows?

        khangol:

        For a windows box, I think you can use start instead of nohup.

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.

Re: Installing a program on a remote server through a web browser.
by locked_user sundialsvc4 (Abbot) on Jan 04, 2011 at 02:31 UTC

    (Thin smile ...)

    If you even imagine that a web site is going to allow a web-page to install software on the server computer . . . you are certifiably daft.

    “What do you think this is, Microsoft Windows?   Really now!”

    ;-)   ;-)   ;-)

      It works, it installs the software, I just can't get the results of the install (success or fail).

        The point, since you missed it, is that you can expect your server will soon run out of disk space because there are too many trojans, worms and spambots installed on it through that web interface.