In a txt file, I have a list of sites that I'd like to visit. Each of them provides a list of pages on the particular site to be visited (when called without page parameter) via list.php. The problem is that the inside loop is getting executed right after the first pass through the outside loop and that causes running multiple instances of chromium browser. What I'd like to achieve is visiting each page and closing the browser after that, then visiting another etc.

while read sites; do 
    wget -qO- "$sites/list.php" | 
        while read page; do 
           chromium "$sites/$page" & sleep 1
           pkill --oldest chromium
           wget -qO- "$sites/list.php?page=$page"
done < sites.txt

closed as off-topic by terdon Nov 11 '15 at 15:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – terdon
If this question can be reworded to fit the rules in the help center, please edit the question.


Don't send chromium to the background:

chromium "$sites/$page" & sleep 1

Keep it in the foreground:

chromium "$sites/$page"
sleep 1
  • And if assuming I need it to be running on the background? I guess making a single loop by combining the URLs before the inner loop, right? – Alexis Nov 11 '15 at 0:02
  • 1
    @Alexis if you run it in the background, you need to use wait. But what's the point? – muru Nov 11 '15 at 0:04

After opening a new session, the code worked as expected, it was just some fluke

UPDATE: to make it reliable, the only thing needed is to increase the sleep interval by a few seconds

Not the answer you're looking for? Browse other questions tagged or ask your own question.