我可以用 bash 打开链接,但我找不到一种方法来每 2 秒一次打开它们并以相同的时间间隔关闭它们。我希望能够在屏幕上看到数百个经常打开的网址。我不在乎这使用什么浏览器。也许这对于我很乐意使用的不起眼的浏览器来说可以很好地工作。
#!/bin/bash
# Check if the required argument / text file is there
if [ $# -ne 1 ]; then
echo "Usage: $0 <text_file>"
exit 1
fi
# Check if file exists
if [ ! -f "$1" ]; then
echo "Error: Text file '$1' not found."
exit 1
fi
# open each url from each line of the text file
while read -r link
do
# Open the link in Google Chrome
google-chrome "$link" &
done < "$1"
您可以创建一个循环,一次打开一个浏览器,并在 X 秒后杀死之前打开的浏览器:
# Read all urls
readarray -t urls < "$filename" # or "$1" in your case
oldproc=0
while (( 1 )); do
# loop over all the urls
for link in "${urls[@]}"; do
google-chrome "$link" &
# store the process id of the opened browser:
newproc=$!
# sleep a little while the new browser opens:
sleep 1
if (( oldproc != 0 )); then
# kill the old browser:
kill $oldproc
fi
# store the new process id to be able to kill it in the next iteration
oldproc=$newproc
# wait for X seconds:
sleep 4
done
done
我在这里先打开新浏览器,然后再杀死旧浏览器,因为打开新浏览器通常需要一点时间。您必须根据自己的喜好调整时间。