CuriousNewbie
CuriousNewbie

Reputation: 329

BASH: How to make a script that update every X seconds and it repeats forever?

lets say i have this line of codes

#!/bin/bash
xidel -se '//span[@class="last original"][1]' 'https://www.cnbc.com/quotes/?symbol=XAU='
exit 0

the output should be around 1,7K+

however, this script is only run once. I want it loop forever every 5 or 10 secs , what should I do?

Upvotes: 0

Views: 723

Answers (2)

Sam Daniel
Sam Daniel

Reputation: 1902

You can do a loop and sleep

while :; do <your_command>; sleep <seconds>; done

Another option is to watch you command

watch -n <seconds> <your command> # use "<command>" if your command contains whitespaces

watch command has some quite nice features which comes out of the box

–errexit : freeze screen when the command failed
-beep: give a beep when the command failed
-differences: to highlight the differences in output.

Upvotes: 2

CuriousNewbie
CuriousNewbie

Reputation: 329

#!/bin/bash

for (( ; ; ))
do

clear #put clear if we don't want the script is executed under the old process
xidel -se '//span[@class="last original"][1]' 'https://www.cnbc.com/quotes/?symbol=XAU='

sleep 5 #Every 5 seconds

done

Upvotes: 1

Related Questions