I'm new to perl and learning to develop my first Perl-CGI HTML page. I have a bash script that run few of the database functions within our organization, part of the script while performing different operations it does show a progress bar displaying (.)dots on the terminal
There is a requirement and now we want the script to be run from HTML page wherein our developers could use the webpage to run the script without actually connecting to the server. After investigating found Perl-CGI is a good option and Initially I had problem with perl based buffering while running the script through perl-CGI. However I fixed the issue following suggestions from other posts by using ($|=1;) to generate un buffered perl output.
After fixing the buffer issue, now I have 2 issues. please see below,
1) while I execute the perl script from terminal the output does display (.)dots, However they appear in wrong order....
2) If I execute from the webpage - output doesn't display (.)dots - however waits until it finishes the function + wrong order In order to help debugging the script - I made sample BASH and PERL to re-generate the same issue, I am attaching the BASH and Perl code here. Please see and advise if we can achieve OUTPUT displaying the progress bar and also in the correct order
Bash_Script: Name: shell_script.shPerl-CGI: Name: perl_script.pl#!/bin/bash ### rundots() { ( trap 'exit 0' SIGUSR1; while : ; do echo -ne '.' >&2; +sleep 0.2; done) & dotpid=$!; } ### stopdots() { kill -USR1 $dotpid; wait $dotpid; trap EXIT; } ### startdots() { echo -e "\nExecuting function >>>> $(tr [a-z] [A-Z] <<< "${FUNCNAME[ 1 + ]}") <<<<<" echo -ne "---->>Script executing, please wait" rundots; trap "stopdots" EXIT; return 0; sleep 0.3} ### main1() { startdots echo -e "display space usage" > /tmp/shell_script.log sleep 4 du -sh * >> /tmp/shell_script.log stopdots } main2() { startdots echo -e "list files," >> /tmp/shell_script.log sleep 4 ls -lsrt >> /tmp/shell_script.log stopdots echo -e "\n\n*********** END OF THE BASH SCRIPT ************" } ### call functions main1 main2
Thanks in advance.#!/usr/bin/perl -w $|=1; use CGI qw(:standard); #use IO::Handle; use FileHandle; print "Content-type: text/html\n\n"; print '<head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Page title</title> <link rel="stylesheet" href="hari.css" type="text/css" media=" +screen"> </head>'; open (my $cmds, "/var/www/cgi-bin/shell_script.sh |"); open (my $LOG, '>', '/tmp/perl.log'); select((select($LOG), $|=1)[0]); while (<$cmds>) { #print "<pre>"; print; print $LOG $_; #print "</pre>"; } close $cmds; close $LOG; print ' </body> </html>';
In reply to Perl CGI + Bash script output in wrong order by h.chris
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |