Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 54b127e809 | |||
| baeda13edd | |||
| ca572b13b4 | |||
| 71881ab882 |
23
README.md
23
README.md
@@ -8,13 +8,33 @@ Bash scripts to check whether a site is available or not, and whether the certif
|
|||||||
|
|
||||||
Usage: urls_check.sh
|
Usage: urls_check.sh
|
||||||
|
|
||||||
|
1. Check whether the certificate is valid or not, using <u>showcert</u> (pip install showcert) if available, else use <u>openssl.</u>
|
||||||
|
2. Check if the url is up or down with it's http_code.
|
||||||
|
|
||||||
|
Required the <u>urls_list.txt</u> file that contain a list of domains:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#https://notif.domain.com
|
||||||
|
#https://ntfy.domain.com
|
||||||
|
https://paperlessngx.domain.com
|
||||||
|
https://pastebin.domain.com
|
||||||
|
|
||||||
|
# comment line to disable checking this url
|
||||||
|
```
|
||||||
|
|
||||||
|
Required the <u>status.txt</u> file to give information about the http code returned.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
302;Found;https://developer.mozilla.org/fr/docs/Web/HTTP/Status/302
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#### 2) validity.sh
|
#### 2) validity.sh
|
||||||
|
|
||||||
Usage: ./validity.sh
|
Usage: ./validity.sh
|
||||||
|
|
||||||
Check whether the certificate is valid or not.
|
Check whether the certificate is valid or not, using <u>showcert</u> (pip install showcert) if available, else use <u>openssl.</u>
|
||||||
|
|
||||||
Required the <u>validity_domains.txt</u> file that contain a list of domains:
|
Required the <u>validity_domains.txt</u> file that contain a list of domains:
|
||||||
|
|
||||||
@@ -23,3 +43,4 @@ domain1.com
|
|||||||
domain2.fr
|
domain2.fr
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or edit the hosts() array in source code.
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ send_gotify_notification() {
|
|||||||
|
|
||||||
send_pushover_notification() {
|
send_pushover_notification() {
|
||||||
echo -e "Sending Pushover notification ..."
|
echo -e "Sending Pushover notification ..."
|
||||||
|
|
||||||
curl -S -s -o /dev/null -F "token=$BASH_APP" \
|
curl -S -s -o /dev/null -F "token=$BASH_APP" \
|
||||||
-F "user=$USER_KEY" \
|
-F "user=$USER_KEY" \
|
||||||
-F "title=$1" \
|
-F "title=$1" \
|
||||||
@@ -204,8 +205,8 @@ fi
|
|||||||
|
|
||||||
# On efface la liste des urls down
|
# On efface la liste des urls down
|
||||||
|
|
||||||
[ -f "./urls_down_list_curl.txt" ] && rm "./urls_down_list_curl.txt"
|
[ -f "$ScriptWorkDir/urls_down_list_curl.txt" ] && rm "$ScriptWorkDir/urls_down_list_curl.txt"
|
||||||
[ -f "./certificats_outdated.txt" ] && rm "./certificats_outdated.txt"
|
[ -f "$ScriptWorkDir/certificats_outdated.txt" ] && rm "$ScriptWorkDir/certificats_outdated.txt"
|
||||||
|
|
||||||
|
|
||||||
check_url() {
|
check_url() {
|
||||||
@@ -220,7 +221,7 @@ check_url() {
|
|||||||
|
|
||||||
else
|
else
|
||||||
echo -e "${redbold}$2. $1 is down${reset} ($response)"
|
echo -e "${redbold}$2. $1 is down${reset} ($response)"
|
||||||
echo "$1 is down ($response)" >> urls_down_list_curl.txt
|
echo "$1 is down ($response)" >> $ScriptWorkDir/urls_down_list_curl.txt
|
||||||
|
|
||||||
# Affichage et description de l'erreur
|
# Affichage et description de l'erreur
|
||||||
status_error "$response"
|
status_error "$response"
|
||||||
@@ -284,11 +285,11 @@ info_certif() {
|
|||||||
array_names+=("$names")
|
array_names+=("$names")
|
||||||
|
|
||||||
#echo "Domain: $domain" >> certificats_outdated.txt
|
#echo "Domain: $domain" >> certificats_outdated.txt
|
||||||
echo "Names: $names" >> certificats_outdated.txt
|
echo "Names: $names" >> $ScriptWorkDir/certificats_outdated.txt
|
||||||
echo "Issuer: $issuer" >> certificats_outdated.txt
|
echo "Issuer: $issuer" >> $ScriptWorkDir/certificats_outdated.txt
|
||||||
echo "Date début: $start" >> certificats_outdated.txt
|
echo "Date début: $start" >> $ScriptWorkDir/certificats_outdated.txt
|
||||||
echo "Date fin: $end" >> certificats_outdated.txt
|
echo "Date fin: $end" >> $ScriptWorkDir/certificats_outdated.txt
|
||||||
echo "" >> certificats_outdated.txt
|
echo "" >> $ScriptWorkDir/certificats_outdated.txt
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
@@ -316,12 +317,12 @@ done
|
|||||||
|
|
||||||
# Affichage des serveurs qui ne répondent pas
|
# Affichage des serveurs qui ne répondent pas
|
||||||
|
|
||||||
if [ -f "./urls_down_list_curl.txt" ]; then
|
if [ -f "$ScriptWorkDir/urls_down_list_curl.txt" ]; then
|
||||||
|
cp "$ScriptWorkDir/urls_down_list_curl.txt" $ScriptWorkDir/urls_down_list_curl.bak
|
||||||
|
url_down=$(cat "$ScriptWorkDir/urls_down_list_curl.txt")
|
||||||
|
|
||||||
if [ "$x" -ne 1 ]; then
|
if [ "$x" -ne 1 ]; then
|
||||||
echo -e "\n${redbold}Url down: ${reset}"
|
echo -e "\n${redbold}Url down: ${reset}"
|
||||||
|
|
||||||
cp "./urls_down_list_curl.txt" urls_down_list_curl.bak
|
|
||||||
url_down=$(cat "./urls_down_list_curl.txt")
|
|
||||||
echo -e "$url_down"
|
echo -e "$url_down"
|
||||||
|
|
||||||
# On affiche uniquement les erreurs rencontrées
|
# On affiche uniquement les erreurs rencontrées
|
||||||
@@ -351,7 +352,7 @@ fi
|
|||||||
if [ -f "./certificats_outdated.txt" ]; then
|
if [ -f "./certificats_outdated.txt" ]; then
|
||||||
echo -e "\n${redbold}Certificat outdated: ${reset}"
|
echo -e "\n${redbold}Certificat outdated: ${reset}"
|
||||||
|
|
||||||
certif_outdated=$(cat "./certificats_outdated.txt")
|
certif_outdated=$(cat "$ScriptWorkDir/certificats_outdated.txt")
|
||||||
echo -e "$certif_outdated\n"
|
echo -e "$certif_outdated\n"
|
||||||
|
|
||||||
if [ "$notif" == "gotify" ];then
|
if [ "$notif" == "gotify" ];then
|
||||||
|
|||||||
34
validity.sh
34
validity.sh
@@ -5,7 +5,8 @@
|
|||||||
|
|
||||||
VERSION="v1.0"
|
VERSION="v1.0"
|
||||||
|
|
||||||
red="\033[1;31m"
|
redbold="\033[1;31m"
|
||||||
|
red="\033[10;31m"
|
||||||
greenbold="\033[1;32m"
|
greenbold="\033[1;32m"
|
||||||
green="\033[0;32m"
|
green="\033[0;32m"
|
||||||
yellow="\033[0;33m"
|
yellow="\033[0;33m"
|
||||||
@@ -46,12 +47,16 @@ ScriptArgs=( "$@" )
|
|||||||
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
|
ScriptPath="$(readlink -f "$0")" # /Users/bruno/Documents/Scripts/bashbirds/bashbirds.sh
|
||||||
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
|
ScriptWorkDir="$(dirname "$ScriptPath")" # /Users/bruno/Documents/Scripts/bashbirds
|
||||||
|
|
||||||
# Domains to check
|
### Domains to check ###
|
||||||
#hosts=("domain.com")
|
#hosts=("domain.com")
|
||||||
if [ -f "$ScriptWorkDir/validity_domains.txt" ]; then
|
hosts=()
|
||||||
|
#if [ ${#hosts[@]} -eq 0 ]; then
|
||||||
|
if [ -f "$ScriptWorkDir/validity_domains.txt" ]; then
|
||||||
readarray -t hosts < "$ScriptWorkDir/validity_domains.txt"
|
readarray -t hosts < "$ScriptWorkDir/validity_domains.txt"
|
||||||
else echo -e "${red}No domain to check !${reset}"
|
else echo -e "${red}No domain to check !${reset}"
|
||||||
fi
|
fi
|
||||||
|
#fi
|
||||||
|
|
||||||
port=443
|
port=443
|
||||||
# Days left before notification
|
# Days left before notification
|
||||||
nday=15
|
nday=15
|
||||||
@@ -95,9 +100,24 @@ send_pushover_notification() {
|
|||||||
|
|
||||||
|
|
||||||
for host in "${hosts[@]}"; do
|
for host in "${hosts[@]}"; do
|
||||||
|
|
||||||
|
url="https://$host"
|
||||||
|
response=$(curl --connect-timeout 10 --max-time 10 --retry 3 --retry-delay 0 --retry-max-time 30 --write-out '%{http_code}' --silent --output /dev/null "$url")
|
||||||
|
|
||||||
|
if [ $(grep -w "200\|301\|302\|303\|307" <<< "$response") ];then
|
||||||
|
|
||||||
if command -v showcert >/dev/null 2>&1; then
|
if command -v showcert >/dev/null 2>&1; then
|
||||||
|
|
||||||
cert=$(showcert $host)
|
cert=$(showcert $host)
|
||||||
|
|
||||||
|
: << 'COMMENTS2'
|
||||||
|
error=$(echo "$cert" | grep "Verification error (use -i)")
|
||||||
|
if [ -n "$error" ]; then
|
||||||
|
echo -e "${redbold}$error${reset}\n${italic}Trying showcert -i $host${reset}"
|
||||||
|
cert=$(showcert -i $host)
|
||||||
|
fi
|
||||||
|
COMMENTS2
|
||||||
|
|
||||||
ip=$(echo "$cert" | grep IP | awk -F": " '{print $2}')
|
ip=$(echo "$cert" | grep IP | awk -F": " '{print $2}')
|
||||||
names=$(echo "$cert" | grep Names | awk -F": " '{print $2}')
|
names=$(echo "$cert" | grep Names | awk -F": " '{print $2}')
|
||||||
issuer=$(echo "$cert" | grep Issuer | awk -F": " '{print $2}')
|
issuer=$(echo "$cert" | grep Issuer | awk -F": " '{print $2}')
|
||||||
@@ -159,4 +179,8 @@ for host in "${hosts[@]}"; do
|
|||||||
|
|
||||||
echo -e "\n"
|
echo -e "\n"
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
|
else
|
||||||
|
echo -e "${red}$host is offline !${reset}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user