Refresh web page in bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Refresh web page in bash script
# 1  
Old 03-27-2016
Refresh web page in bash script

hello,
I am trying to refresh my web page which is created in bash script.
I have a HTML page which when press a button calls a bash script. this bash script created the same page with dynamic data.
When pressing the button I am calling to a function that set time out of 7 seconds and and after 7 seconds it should call a function that simulate a button click and this should refresh the page. But this does not work. any advise?

HTML Code:
HTML Code:
<!doctype html>
<html>
  <head>
<meta http-equiv="refresh" content="10"> 
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
  </head>
  <script>
      function ClickRefresh()
        {    
           window.top.location.reload();
            document.getElementById("refreshbtn")[0].click();
        }
        function TimerRefresh()
        {
                window.setTimeout(ClickRefresh, 7000);
        }
   </script>
  <body>
    <form method="get" action="cgi-bin/createStatArea.sh" onsubmit="window.top.location.reload();" name="testStatusForm" >
    <div style="float:left; position:relative; width:250px; margin right:40px"> 
        <fieldset>
          <legend><h2>Test status</h2></legend>
        <textarea name="testStatus" id="testStatus" readonly>
            Please select the tests and set test parameters.
        </textarea><br><br>
        <button id="refreshbtn" onclick="TimerRefresh()">REFRESH</button><br><br>
        </fieldset>        
     </div>
    </form>
  </body>
</html>
BASH Code:
Code:
#!/bin/bash
printf "<!doctype html>"
printf "<html>"
printf     "<head>"
printf "<meta http-equiv="refresh" content="10">"
printf "<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">"
printf "</head>"
printf "<body>"
printf "<script>"
printf      "function ClickRefresh()"
printf         "{"
printf         "window.top.location.reload()";
printf        "document.getElementById("refreshbtn")[0].click();"
printf         "}"

printf      "function TimerRefresh()"
printf         "{"
printf        "window.setTimeout("ClickRefresh", "7000");"
printf         "}"
printf "</script>"
printf "<form method="get" action="cgi-bin/createStatArea.sh" onsubmit="window.top.location.reload"();"" name="testStatusForm">"
printf     "<div style=float:left; position:relative; margin-right:40px>"
printf         "<fieldset>"
printf            "<legend><h2>Test Status</h2></legend>"
printf "         <textarea name="testStatus" id="testStatus" rows="10" cols="30" readonly>"
printf "$(date +%d:%m:%Y) $(date +%X)\n"
printf "        </textarea><br><br>"
printf "<button id="refreshbtn" onclick="TimerRefresh"()"">REFRESH</button><br><br>"
printf "</div>"
printf "</form>"
printf "</body>"
printf "</html>"


Last edited by Scrutinizer; 03-27-2016 at 12:29 PM.. Reason: code tags
# 2  
Old 03-27-2016
Usually CGI need to return content type. And using HERE method it's easier to write web page with variable and command expand. Rest is html/javascript problem, not scripting.

Code:
#!/bin/bash
cat <<EOF
Content-type: text/html

<!doctype html>
<html>
  <head>
<meta http-equiv="refresh" content="10">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
  </head>
  <script>
      function ClickRefresh()
        {
           window.top.location.reload();
            document.getElementById("refreshbtn")[0].click();
        }
        function TimerRefresh()
        {
                window.setTimeout(ClickRefresh, 7000);
        }
   </script>
  <body>
    <form method="get" action="cgi-bin/createStatArea.sh" name="testStatusForm" >
    <div style="float:left; position:relative; width:250px; margin right:40px">
        <fieldset>
          <legend><h2>Test 2 status</h2></legend>
        <textarea name="testStatus" id="testStatus" readonly>
            $(date) $(hostname)
        </textarea><br><br>
        <button id="refreshbtn" onclick="TimerRefresh()">REFRESH</button><br><br>
$(date)
        </fieldset>
     </div>
    </form>
  </body>
</html>

EOF

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Random web page download wget script

Hi, I've been attempting to create a script that downloads web pages at random intervals to mimic typical user usage. However I'm struggling to link $url to the URL list and thus wget complains of a missing URL. Any ideas? Thanks #!/bin/sh #URL List url1="http://www.bbc.co.uk"... (14 Replies)
Discussion started by: shadyuk
14 Replies

3. UNIX for Dummies Questions & Answers

BASH - Counting word occurrences in a Web Page

Hi all, I have to do a script bash (for university) that counts all word occurrences in a specific web page. anyone can help me?. Thanks :) (1 Reply)
Discussion started by: piacentero
1 Replies

4. Shell Programming and Scripting

How to refresh a graphical display through bash script

Hi folks , I need to display a message graphically using a messagebox or textbox through bash script. However the message should be keep changing every 4 secs . I input the message from a file and use "gxmessage" to display it . gxmessage -nofocus -center -title "Welcome screen" -geometry... (3 Replies)
Discussion started by: ddspark
3 Replies

5. HP-UX

Help running a unix script from a web page

First, let me state that I am completely out of my realm with this. I have a server running HPUX. I'm not even sure if this can be considered a UNIX question and for that let me apologize in advance. I need to create a web page where a client can input 2 variables (i.e. date and phone number).... (0 Replies)
Discussion started by: grinds
0 Replies

6. Shell Programming and Scripting

How to input a number in a web page and pass to a script?

I am working on an embedded linux router and trying to make a webpage where the user can input a desired number of CPE and have a script update that number on the router. I have a CLI where I can log in and type the following to change that number echo "20">/proc/net/dbrctl/maxcpe which then... (7 Replies)
Discussion started by: BobTheBulldog
7 Replies

7. Shell Programming and Scripting

Perl script to copy contents of a web page

Hi All, Sorry to ask this question and i am not sure whether it is possible. please reply to my question. Thanks in advance. I need a perl script ( or any linux compatible scripts ) to copy the graphical contents of the webpage to a word pad. Say for example, i have a documentation site... (10 Replies)
Discussion started by: anand.linux1984
10 Replies

8. Shell Programming and Scripting

how to redirect to a web-page by shell script

Dear all, I am calling a korn shell script(CGI script) by a web-page. This shell script do some checking in a unix file and return true or false. Now within the same script, If it returns true then I want to redirect to another web-page stored in htdocs directory. Example: Login page sends a... (3 Replies)
Discussion started by: ravi18s
3 Replies

9. Shell Programming and Scripting

CGI: refresh page and timeout

Hi, I've been able to put together an HTML page that calls on a cgi program (via ksh) to do some server side processing, then send it back to the user's browser window. The script basically tails a log file and refreshes every # seconds (user chosen) by using the "refresh" meta tag (html). My... (0 Replies)
Discussion started by: man
0 Replies

10. Shell Programming and Scripting

running shell script thru WEB page ....

....passing variable via list... here 's the HTML code extract : **************** <form method=post action=http://servername/cgi-bin/cgi-comptage_diff.ksh> <table border...........> .............. </table> <table bgcolor=#FFFFFF width="980"> ... (6 Replies)
Discussion started by: Nicol
6 Replies
Login or Register to Ask a Question