bash - CGI script skipping source command -
i trying write cgi write html file don't have run script every time want see information.
#!/bin/bash echo "content-type: text/html" echo "" echo "<html>" echo "<head><title>status</title></head>" echo "<body>" ./auto.sh > ../secure/status.html echo "redirecting..." echo "<script language="javascript">window.location.href="../secure/status.html";</script>" echo "</body></html>"
however, when direct browser page, page source shows this, didn't run redirect command, , doesn't redirect...
<html> <head><title>status</title></head> <body> redirecting... <script language=javascript>window.location.href = ../secure/status.html;</script> </body></html>
what doing wrong? thanks!!
edit: auto.sh
#!/bin/bash echo "<html><head><title>status</title></head><body><pre>" echo "$(date)" echo "" failed=$(sudo cat /var/log/secure | grep "$(date +"%b %d")" | grep "sshd" | grep "failed") accepted=$(sudo cat /var/log/secure | grep "$(date +"%b %d")" | grep "sshd" | grep "accepted") speed=$(python /script/speedtest-cli --server 4128 | grep "download:\|upload:") ban=$(sudo cat /var/log/fail2ban.log | grep "$(date +"%y-%m-%d")" | grep "ban") echo "##########failed##########" echo "$failed" echo "" echo "##########accepted##########" echo "$accepted" echo "" echo "##########banned##########" echo "$ban" echo "" echo "##########speed##########" echo "$speed" echo "" echo "##########storage##########" echo "$(df -h)" echo "" echo "##########memory##########" echo "$(free -m)" echo "" echo "<a href="../cgi-bin/status.cgi">refresh</a>" echo "</pre></body></html>"
i put redirect code (including script tag) in <head>
of document.
i amend bash script puts destination in double-quotes (rendering output as) window.location.href="../secure/status.html";
single-quotes ok too. seems bash script usage of quotes not quoting items trying do.
lastly, if want user seeing words "redirecting" should invoke kind of time delay in javascript code.
try : echo "<script type='text/javascript'>window.location.href='../secure/status.html';</script>"
i took small part of auto.sh file , redirected output file.
#!/bin/bash # subset of file auto.sh echo "<html><head><title>status</title></head><body><pre>" echo "$(date)" echo "" failed="failed" accepted="accepted" ban="ban" echo "##########failed##########" echo "$failed" echo "" echo "##########accepted##########" echo "$accepted" echo "" echo "##########banned##########" echo "$ban" echo "" echo '<a href="../cgi-bin/status.cgi">refresh</a>' echo "</pre></body></html>"
note single-quotes in href line.
then, executed on command line: sh auto.sh > status.html
lastly, executed cat status.html
, got this...
<html><head><title>status</title></head><body><pre> thu, oct 22, 2015 3:09:43 pm ##########failed########## failed ##########accepted########## accepted ##########banned########## ban <a href="../cgi-bin/status.cgi">refresh</a> </pre></body></html>
is you're trying do?
Comments
Post a Comment