I'm a sysadmin intern for a web hosting company and I'm trying to figure out how to get this task accomplished so I'll be as descriptive as possible.
We have /etc/blockedips and /etc/donotblock
I want to create a script that I can eventually setup in cron that will run like once every hour that scans both files and compares them and either a) send an alert out (we use watchdog) or b) automatically removes the IP inside /blockedips that matches what it shouldnt be blocking inside /donotblock as we have a lot of other techs who always add IPs that shouldnt be blocked.
The problem I'm having as I am new to scripting is that I can easily run a simple grep command for straight IP addresses (ie: 220.127.116.11 will easily match across both files) but I cant figure out how to do the following:
Lets say our companies IP block is 18.104.22.168/24. I don't want to put in every single address inside /donotblock, I just want the script to match any IP that is 99.10.10.* and I am drawing a blank on how to accomplish this.
Can someone point me in the right direction with this? Edit: Sample
So the files look like so:
22.214.171.124/18 126.96.36.199/20 188.8.131.52/24 184.108.40.206/20
lets say some tech added into the /blocked_ips
220.127.116.11, I just want the script to look for "73.16.32.*" to make up for that whole subnet.
Speaking to the lead engineer he prefers to just have the script automatically remove the IP inside blocked_ips that match whats in donotblock