In this part we will create a directory, copy the script, edit the script and test the script
All pages in this serie:
Steps on this page:
Create a directory in a directory where you want to place the script.
On SSH you can nivate to the directory where you want to create the directory for the IP-logger script and execute:
mkdir ip-logger
In my case I created the directory at /data/local, so the whole path for the IP-logger directory would be /data/logger/ip-logger. From now on I will use this example path.
Copy the script to the directory. On Windows WinSCP is the easiest way to get the script copied to the right location.
You can find the script within the attachments on the bottom of this page. You may freely edit the script to suit your whishes and needs. I would be happy when you inform me about the changes you made!
Based on the example path above the whole path to the script will be /data/local/ip-logger/ip-logger.sh.
You will need to edit some variables within the script.
It's best to edit the script with the built-in editor of WinSCP or on a SSH session with Nano.
You can install Nano with the command
opkg install nano
You can open Nano with the script by execute the following command when you are at the correct directory where the IP-logger script is being placed (with the example path that would be /data/local/ip-logger):
nano ip-logger.sh
All variables are defined at the top of the script. They are explained on this section. All variables are defined between quotes except IPLOGGER_ENABLELOG.
At the bottom there are a few lines which you have to comment out or edit.
Just below the line
function pushbullet_inform_new {
you will find the following 3 lines:
# Comment the following 2 lines if you don't want to use a second pushmessage to an e-mailaddress. Otherwise change the e-mailaddress to the one you want to send the pushmessage to.
log "Sending e-mail using Pushbullet.";
curl -k --silent --header "Access-Token: $IPLOGGER_PUSHBULLET_TOKEN" --header "Content-Type: application/json" --data-binary "{\"title\":\"IP-adress of $IPLOGGER_SERVERNAME changed\",\"body\":\"The IP-adress of $IPLOGGER_SERVERNAME has changed from $GETOLDEXTIP to $GETEXTIP at $(date +"%m-%d-%Y %H:%M:%S").\",\"type\":\"note\",\"email\":\"youre-mailaddress@goes.here\"}" --request POST https://api.pushbullet.com/v2/pushes > /dev/zero;
If you want top recieve an e-mail regarding the change of the external IP-address you can leave this 3 lines in tact. The only thing you have to do is changing the phrase youre-mailaddress@goes.here into your own e-mail address which isn't in use as a Pushbullet account (otherwise you will recieve a pushmessage twice).
Hint: GMail has the option to add "+yourtag" afther the prefix of your e-mail address. So if your e-mail address is mymailaddress@gmail.com you could use mymailaddress+iplogger@gmail.com to recieve the e-mails on and to avoid delivering as pushmessage. Both mailaddresses redirects to the same mailbox. You can even add rules to automatically filter and add labels to the mails.
If you don't want to recieve e-mails you have to add a square (#) before the two lines who doesn't have a square at the beginning of the lines.
Repeat above instruction for the same 3 lines just below the line
function pushbullet_inform_updated {
To be able to execute the script it needs execute rights.
You can provide the execute rights by executing the command:
chmod +x ip-logger.sh
from the directory where the script is placed. With the example path that would be /data/local/ip-logger.
Now the script is ready to test.
From the IP-logger directory (with the example path that would be /data/local/ip-logger) you can execute the script with the following command:
./ip-logger.sh
When you made a typo bash will inform you on which line contains the error. When in doubt how to solve the error you can contact me at j [dot] maathuis+iploggercontact [at] gmail [dot] com (replace "[character]" by its corresponding character without braces) and maybe I can help you out, but I can not provide any guarantees on that.
When you don't see any strange behaviour you did install the script correctly.
Proceed with IP-logger - Part 4: Adding cronjob to crontab.
Below are the files included with this projectpage.