- 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/machineIP
so that you can access the panel anytime without any issue.
-
Put the
cpip.sh
file to anyhwere you like. E.g.,/home/scripts
. -
For crontab:
- Open terminal.
- Give the file execute permission, type/ copy
sudo chmod +x /location/cpip.sh
pressEnter
. - Open crontab, type/ copy
crontab -e
pressEnter
. - 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
Esc
and typewq
then pressEnter
. - Setting up cron is completed!
- For systemd timer:
- Open terminal.
- Give the file execute permission, type/ copy
sudo chmod +x /location/cpip.sh
pressEnter
. - Create a systemd service unit, type/ copy
/etc/systemd/system/cpip.service
pressEnter
. - Copy all of the content from
cpip.service
down below. - After setting service unit press
Esc
and typewq
then pressEnter
. - Create a systemd timer unit at the same location of service unit, type/ copy
/etc/systemd/system/cpip.timer
pressEnter
. - Copy all of the content from
cpip.timer
down below. - If you want to run the timer unit every minute, edit/ copy
*:0/1
(This is given on thecpip.timer
file). - 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
Esc
and typewq
then 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 AVAILABILITY
and 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 IP
and shows[CyberPanel IP] GETTING MACHINE IP...
.
- If
machineIP
file is present then it will show[CyberPanel IP] MACHINE IP: 1.2.3.4
. - If
machineIP
file is not present then it will show[CyberPanel IP] MACHINE IP FILE NOT FOUND!
and exit.
- Now it will check for
CURRENT IP
and 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 IP
due 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, 3
because 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
crontab
orsystemd timer
both will create huge size log files! It will be better if you uselogrotate
to keep the log files at a minimum size.