Sometimes, during system administration or web application repair, we had to watch the status code it returned. To check a website’s status code, you can run the following:

$ curl --silent --write-out "%{http_code}" --output /dev/null <Your URL>

If you need to watch the status code continuously, Linux/MacOS has a watch Application. You can install it with the following command:

$ sudo apt install watch # Debian/Ubuntu
$ sudo yum install watch # CentOS/RedHat/Fedora
$ brew install watch # MacOS

Now, you can run a combined command with the previous command and watch like below:

$ watch  curl --silent --write-out "%{http_code}" --output /dev/null <Your URL>

By default, it continuously runs in every 2 seconds; you can control it -n <seconds> option, like below:

$ watch -n 5 curl --silent --write-out "%{http_code}" --output /dev/null <Your URL>

You can stop watching if the status code changes, the command is:

$ watch -g -n 5 curl --silent --write-out "%{http_code}" --output /dev/null <Your URL>

You can add a beep sound when the status code is changed, and the watch is stopped:

$ watch -g -n 5 curl --silent --write-out "%{http_code}" --output /dev/null <Your URL>; echo -e "\a"

Sometimes, a single beep is hard to notice; you can add multiple beep sounds:

$ watch -g -n 5 curl --silent --write-out "%{http_code}" --output /dev/null <Your URL>; for i in {1..5}; do echo -e "\a"; sleep .5; done