Example bash script fro status server and website

Example bash script fro status server and website

Here is an example of a simple bash script that can be used to check the status of a server:

#!/bin/bash

# Define the server address
server=http://example.com

# Use the curl command to check the server's HTTP response code
response=$(curl -s -o /dev/null -w "%{http_code}" $server)

# Check if the response code is 200 (OK)
if [ $response -eq 200 ]; then
  echo "Server is up and running!"
else
  echo "Server is down!"
fi

This script uses the curl command to check the HTTP response code of the server specified in the server variable. The -s flag is used to make the curl command silent, and the -o /dev/null flag is used to discard the output. The -w "%{http_code}" flag is used to display the HTTP response code.

You can change the server address to your own server and the script will check the status of the server and give you the response. This script is only checking the HTTP response and not the actual functionality of the server.

It is also possible to include other checks like CPU, Memory, Disk usage and overall health of the server.

It is important to note that you need to have curl installed on your system, if not you can install it by running sudo apt-get install curl on Ubuntu/Debian based systems or sudo yum install curl on Red Hat based systems.