On PBX, make sure the kamitserviceuser creads were created, including visudo command.
Log in as KamitServiceUser on ERX
`su kamitserviceuser`
create a ~/scripts folder
`mkdir ~/scripts`
inside ~/scripts folder, create a file called “IPMonitor.sh”
`touch ~/scripts/IPMonitor.sh`
Make the script exicutable
`sudo chmod +x ~/scripts/IPMonitor.sh`
Edit the script
`nano ~/scripts/IPMonitor.sh`
Add the following infomation: (Change both vPBXIP, vLOCATION)
`#!/bin/bash
IPNow=$(curl -s ifconfig.me)
LOGFILE="/home/kamitserviceuser/scripts/IPMonitor.log"
vLOCATION="Axis Post Falls"
vPBXIP="216.128.182.136"
if test -f "$LOGFILE"; then
echo "Valid log file found."
else
echo "New Log File - $(date +%F-%T)" >$LOGFILE
fi
if ssh kamitserviceuser@$vPBXIP "sudo iptables -nvL | grep -q $IPNow"; then
echo "IP found ($IPNow), No Change - $(date +%F-%T)" >>$LOGFILE
else
echo "Change - $(date +%F-%T)" >>$LOGFILE
echo " Old IP: $(cat $FILE)">>$LOGFILE
echo " New IP: $IPNow ">>$LOGFILE
echo " Updating PBX iptables with rule comment: $vLOCATION - '$(date +%F-%T)">>$LOGFILE
ssh kamitserviceuser@$vPBXIP "sudo iptables -I INPUT 1 -s $IPNow -j ACCEPT -m comment --comment '$vLOCATION - '$(date +%F-%T)"
fi`
Add the script to crontab
`crontab -e`
Add this entry
`*/3 * * * * /home/kamitserviceuser/scripts/IPMonitor.sh`