Script to open index.html from multiple folders

3

How to make a script in bash that:

  • Based on this example url: link
  • Select the 12620 folder.
  • Open the index.html of this folder in a Firefox tab in Kali (Debian)
  • Select folder 12620, add +1, getting 12621, and open index.html from that folder in a new tab.
  • And so on.

I thought of something like:

FOLDER=12620
for (($FOLDER, $FOLDER =< 12660, $FOLDER++))
  do
    firefox -new-tab http://www.exemple.com/1/43530/.'$FOLDER'./index.html
  done

I did in JavaScript, just wanted to switch to Bash and open in Firefox

<!DOCTYPE html>
<html>
<body>

<button onclick="abrirHTML()">Abrir</button>

<script>
function abrirHTML() {
var folder = 12690;



for (folder = 12690; folder < 12695; folder++) {
    window.open("http://www.exemple.com/1/43530/" + folder + "/index.html");
}
}
</script>


</body>
</html>
    
asked by anonymous 20.09.2015 / 21:32

2 answers

2

A simple example of a bash loop would look like this:

 #!/bin/bash 
 COUNTER=12690
 while [  $COUNTER -lt 12695 ]; do
     firefox -new-tab "http://www.exemple.com/1/43530/${COUNTER}/index.html"
     let COUNTER=COUNTER+1 
 done

Source and tips: link

    
20.09.2015 / 23:40
0

I know the question does not involve exactly Python, but since Python is present in almost every linux, why not script it in that language? Well, here's the Python version, but I'll post it later on Bash:

import os, sys
import webbrowser
import urllib2 as net
from urllib2 import HTTPError

FOLDER   = 12620
BASE_URL = 'http://localhost/folders'
BASENAME = 'index.html'

while True:
    try:
        url = "{}/{}/{}".format(BASE_URL, FOLDER, BASENAME)
        net.urlopen(url)
        webbrowser.open(url)
    except HTTPError:    
        break
    FOLDER += 1

sys.exit()
    
21.09.2015 / 00:02