Im a bit of a bash novice, so apologies if this is easy Im making a bash script which will run per minute to check that services are up (mysql, redis and so on) per site (we use Glances at the server level)
I would ideally like to have the script be self sufficient, and thus one of those is the ability to read the config file for that site
So, im looking for something like this, but I know this isnt quite right:
FILE=./wp-config.php
if test -f "$FILE"; then
db_user=`cat wp-config.php | grep DB_USER | cut -d \' -f 4`
db_password=`cat wp-config.php | grep DB_PASSWORD | cut -d \' -f 4`
fi
FILE=./.env
if test -f "$FILE"; then
db_user=$(read_var DB_USERNAME .env)
db_password=$(read_var DB_PASSWORD .env)
fi
Explained in written text:
If ( in this directory a file named wp-config.php exists) // aka a wordpress site
- Get the DB_USER value
- Get the DB_PASSWORD value
If ( in this directory a file named .env exists) // aka a laravel site
- Get the DB_USER value
- Get the DB_PASSWORD value
The script will then continue to connect to the database and do various things to check and then post that information onto the central monitoring system
Could anyone help me at all get that right, or explain the mistakes What I have there is from extensive googling!!!