in reply to Re^7: show a message only during the sleep time
in thread show a message only during the sleep time

I removed this line:
exit($cc);
and still get the same error in the browser

from command line:
# perl ntop4.cgi + [Mon Jul 25 14:27:27 2005] ntop4.cgi: Unrecognized escape \d passed th +rough at ntop4.cgi line 53. <html> <head> <title>ntop startup script</title> <STYLE TYPE='text/css'> h3 { color: red } a { text-decoration: none; font: bold 14pt/16pt Ariel, serif } a:hover { color: red } /* when mouse is over link */ </style> <script language="javascript"> function hideWaitMsg(){ var obj = getElementById('wait_msg_text'); obj.visible = false; } </script> </head> <body bgcolor='#c0c0d0' onLoad="hideWaitMsg()"> <center> <p><br></p> <p><br></p> <div id="wait_msg_text">pls wait, ntop will be started</div> Mon Jul 25 14:27:28 2005 Initializing gdbm databases <font face="arial,helvetica" size=2 color="#006600">status: +</font> ntop<br><br> <font face="arial,helvetica" size=2 color="#FF0000"> pls do not forget to shutdown, if you're not using </font> <p><br></p>pls wait for 5 seconds before you click on this link: <br><br><a href="https://192.168.0.3:3001"><b><U>NTOP</b></U></a> <p><br></p><p><br></p><p><br></p><p><br></p>Maintained by <a href="mai +lto:admin@domain.net"><font face="arial,helvetica" size=3> admin</a></font> </center></body></html>

Apache error log says:
[Mon Jul 25 14:30:04 2005] [error] [client 192.168.0.105] [Mon Jul 25 +14:30:04 2005] ntop4.cgi: Unrecognized escape \\d passed through at / +usr/local/www/cgi-bin/ntop/ntop4.cgi line 53. [Mon Jul 25 14:30:04 2005] [error] [client 192.168.0.105] malformed he +ader from script. Bad header=<html>: ntop4.cgi
greetings cc

Replies are listed 'Best First'.
Re^9: show a message only during the sleep time
by davidrw (Prior) on Jul 25, 2005 at 13:37 UTC
    So what's happening is that there's that error, and that's getting sent to the web server (to be sent to the browser) first. But the web server must get valid http headers first. so two things to fix:
    • 1) this line is causing the error (i think you meant to escape the '@', not the 'd'):
      print "Maintained by <a href=\"mailto:admin@\domain.net\"><font face=\ +"arial,helvetica\" size=3> admin</a></font>\n";
    • 2) You need to print HTTP headers before you start printing your content (the html code). look at the CGI docs for how to do this (alsoo look in the CGI section of the Tutorials for more good stuff)
      I solved the problem.
      There was a problem with JavaScript.

      Now it works perfectly:
      #!/usr/bin/perl -w use strict; use warnings; use CGI; my $query = new CGI; use CGI::Carp qw(fatalsToBrowser); $|=1; print $query->header; print "<html>\n"; print "<head>\n"; print "<title>ntop startup script</title>\n"; print "<STYLE TYPE='text/css'>\n"; print "h3 { color: red }\n"; print "a { text-decoration: none; font: bold 14pt/16pt Ariel, serif }" +; print "a:hover { color: red } /* when mouse is over link */"; print "</style>\n"; print "<SCRIPT LANGUAGE = \"JavaScript\">\n"; print "<!-- \n"; print "function hideWaitMsg(){ document.getElementById('wait_msg_text').style.visibility = + 'hidden'; }\n"; print "// -->\n"; print "</SCRIPT>\n"; print "</head>\n"; print "<center>"; print "<body bgcolor=\"#c0c0d0\" onLoad=\"hideWaitMsg()\"><br>\n"; print "<div id=\"wait_msg_text\">pls wait, ntop will be started !</div +> \n"; print "<p><br></p>"; system `/usr/local/www/cgi-bin/ntop/ntop.sh stop` or die "cannot stop +ntop: $!"; sleep(8); my $cc = `sudo /usr/local/www/cgi-bin/ntop/ntop.sh start` or die "cann +ot start ntop: $!"; print "<font face=\"arial,helvetica\" size=2 color=\"#006600\">status: +</font> ",$cc,"<br><br>\n"; print "<font face=\"arial,helvetica\" size=2 color=\"#FF0000\"> pls do not forget to shutdown, if you're not using </font> \n"; print "\n"; print "<p><br></p>"; print "pls wait for 5 seconds before you click on this link:\n"; print "<br><br>"; print "<a href=\"https://192.168.0.3:3001\"><b><U>NTOP</b></U></a>\n"; print "<p><br></p>"; print "<p><br></p>"; print "<p><br></p>"; print "Maintained by <a href=\"mailto:admin@\domain.net\"><font face=\ +"arial,helvetica\" size=3> admin</a></font>\n"; print "</center>"; print "</body>"; print "</html>"; exit($cc);

      greetings
      cc
        system `/usr/local/www/cgi-bin/ntop/ntop.sh stop`
        Either pick backquotes (because you want to capture the output) or system (because you want to run the child process), but not both. You're taking the output of ntop, and running it as yet another command, ignoring the results.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.