Introduction
There may be a need to check if a configuration file is in place and if it is missing to put back the original. This could be expanded to check the file via md5sum to ensure it is actually the same exact file as well if needed.
Procedure
In this example, I am going to use the CloudFlare file that gets stored in /root/.cpanel/datastore/cf_api and create a script to check if it exists and to copy back a backup if it doesn't.
First make a backup:
mkdir /root/cf/
cp -ax /root/.cpanel/datastore/cf_api /root/cf/
Next the script:
#!/bin/bash
if [[ ! -f /root/.cpanel/datastore/cf_api ]];
then
cp -ax /root/cf/cf_api /root/.cpanel/datastore/
fi
The script is literally if /root/.cpanel/datastore/cf_api does not exist then copy /root/cf/cf_api to /root/.cpanel/datastore/.
Place the script into a file of /root/cf/chcheck.sh and then set executable permissions with
chmod 750 /root/cf/chcheck.sh
Lastly, that can be placed into root's crontab to be run every minute to ensure the file exists and only replaces the file if it doesn't. Please refer to the following on adding a cron job for user root.