- NO LONGER MAINTAINED!
- This script will check if external IP is changed or not and will update the external IP of this file
/etc/cyberpanel/machineIPso that you can access the panel anytime without any issue.
-
Put the
cpip.shfile to anyhwere you like. E.g.,/home/scripts. -
For crontab:
- Open terminal.
- Give the file execute permission, type/ copy
sudo chmod +x /location/cpip.shpressEnter. - Open crontab, type/ copy
crontab -epressEnter. - If you want to run the job every minute, type/ copy
* * * * * /location/cpip.sh. - If you want to run the job every 5 minute, type/ copy
5 * * * * /location/cpip.sh. - If you want more time flexibility then goto this link.
- After setting cron press
Escand typewqthen pressEnter. - Setting up cron is completed!
- For systemd timer:
- Open terminal.
- Give the file execute permission, type/ copy
sudo chmod +x /location/cpip.shpressEnter. - Create a systemd service unit, type/ copy
/etc/systemd/system/cpip.servicepressEnter. - Copy all of the content from
cpip.servicedown below. - After setting service unit press
Escand typewqthen pressEnter. - Create a systemd timer unit at the same location of service unit, type/ copy
/etc/systemd/system/cpip.timerpressEnter. - Copy all of the content from
cpip.timerdown below. - If you want to run the timer unit every minute, edit/ copy
*:0/1(This is given on thecpip.timerfile). - If you want to run the timer unit every 5 minute, edit/ copy
*:0/5. - If you want more time flexibility then goto this link.
- After setting timer unit press
Escand typewqthen pressEnter. - Reload systemd, type/ copy
sudo systemctl daemon-reload. - Enable timer unit, type/ copy
sudo systemctl enable cpip.timer. - Start timer unit, type/ copy
sudo systemctl start cpip.timer. - Setting up systemd timer is completed!
This is a verbal representation of the script explaining how the script works.
-
Script will start executing and shows
[CyberPanel IP] IP CHECK INITIATED.... -
Now it will check for
INTERNET AVAILABILITYand shows[CyberPanel IP] CHECKING FOR INTERNET AVAILABILITY....
- If internet is available then it will show
[CyberPanel IP] INTERNET IS AVAILABLE!and go to next step. - If internet is not available then it will show
[CyberPanel IP] INTERNET IS UNAVAILABLE!and exit.
- Now it will check for
MACHINE IPand shows[CyberPanel IP] GETTING MACHINE IP....
- If
machineIPfile is present then it will show[CyberPanel IP] MACHINE IP: 1.2.3.4. - If
machineIPfile is not present then it will show[CyberPanel IP] MACHINE IP FILE NOT FOUND!and exit.
- Now it will check for
CURRENT IPand shows[CyberPanel IP] CHECKING FOR NEW IP....
- If public IP is unchanged and valid then it will show
[CyberPanel IP] NO NEW IP DETECTED!and exit. - If public IP is changed and valid then it will show
[CyberPanel IP] NEW IP DETECTED!and go to next step. - If selected interface can not check for
Current IPdue to curl error or IP is invalid then it will show[CyberPanel IP] CHECKING FOR NEW IP FAILED!and exit.
- Now it will check for
IP change. if it get's new IP from Step 4 it will show[CyberPanel IP] UPDATING IP....
- If it failed to update the IP then it will show
[CyberPanel IP] IP UPDATE FAILED!,[CyberPanel IP] SAVING LOG...and exit. - If it succeeded to update the IP then it will show
[CyberPanel IP] IP UPDATED TO: 1.2.3.4,[CyberPanel IP] SAVING IP...,[CyberPanel IP] SAVING LOG...and exit.
- I have written the instructions based on CentOS 7.6.x.
- Files name are started with
0, 1, 2, 3because of orderly manner. - I am new to this Scripting Business that's why if I made any mistake please point out any issue!
- Keep in mind that whether you use
crontaborsystemd timerboth will create huge size log files! It will be better if you uselogrotateto keep the log files at a minimum size.