Script to open index.html from multiple folders

Asked

Viewed 108 times

3

How to make a script in bash that:

  • Based on this example url: http://www.exemple.com.br/1/43530/12620/index.html
  • Select the folder 12620.
  • Open the index.html of this folder in a Firefox tab in Kali (Debian)
  • Select the additional 12620 folder +1, getting 12621, and open the index.html of that folder in a new tab.
  • And so on and so forth.

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 it in Javascript, just wanted to pass 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>

  • Welcome to Sopt. Edith your question and show us what you have tried. I also recommend reading How to create a Minimum, Complete and Verifiable example

  • I edited @Jéfersonbueno

  • @Kaka And did your script not work? Any errors? Have you considered using Python for this script instead of BASH?

  • Will you open 5 new tabs? 12690 to 12695? Would this be the loop? I didn’t understand why javascript values were different from your bash, js you used 12690 and bash used 12660.

  • @Guillermo hermetypo

2 answers

2


A simple example of loop with bash would be 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: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html

0

I know the question does not exactly involve Python, but since Python is present in almost all linux, why not do the script 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()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.