Open API call ans bash script

Discussion in 'Join' started by PierreDurrr, Jul 26, 2019.

  1. PierreDurrr

    PierreDurrr New Member

    Joined:
    Jul 26, 2019
    Messages:
    5
    Likes Received:
    0
    Hi,
    since my ISP give me a dynamic ip address, i would like to get notified each time the address get renewed.
    I made a shell script that do the job pretty well, but i'm trying to be a bit more precise and have the new ip in my notification.

    A little help ?

    Code (Text):

    #!/bin/bash

    # On rapatrie http://checkip.dyndns.com/ dans le fichier index.html
    wget http://checkip.dyndns.com/ -O /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/index.html

    # On extrait l'adresse IP du fichier index.html et on la place dans le fichier IPactuelle.txt
    cat /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/index.html | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' > /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/IPactuelle.txt

    # On stocke l'IP contenue dans le fichier IPactuelle.txt dans la variable $IPactuelle
    IPactuelle=$(cat /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/IPactuelle.txt)

    # On stocke l'IP contenue dans le fichier IPenregistree.txt dans la variable $IPenregistree
    IPenregistree=$(cat /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/IPenregistree.txt)

    # Si les variables $IPactuelle et $IPenregistree sont différentes et si $IPactuelle n'est pas vide
    if [ "$IPactuelle" != "$IPenregistree" ] && [ "$IPactuelle" != "" ]
            then
                   
    # On remplace le fichier IPenregistree.txt par IPactuelle.txt
    cp /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/IPactuelle.txt /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/IPenregistree.txt
                   
    # On envoie la notification Join
    curl "https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?deviceId=group.all&text=adresse%20IP%20publique%20de%20la%20maison%20vient%20de%20changer.%20Penser%20%C3%A0%20mettre%20%C3%A0%20jour%20les%20param%C3%A8tres%20du%20VPN.%20Nouvelle%20adresse%20%3A%20%24IPactuelle&title=IP%20Maison&apikey=0000000000" > /dev/null
                   
    # On ajoute une ligne dans le log qui contient la date, l'heure et l'adresse IP
    echo `date +\%Y\%m\%d` - `date +\%T` - IP : $IPactuelle >> /var/log/notify-change-IP/notify-change-IP-`date +\%Y\%m`.log
    fi

    # On supprime le fichier index.html
    rm /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/index.html
     
     
  2. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    8,709
    Likes Received:
    736
    What part are you having trouble with exactly?
     
  3. PierreDurrr

    PierreDurrr New Member

    Joined:
    Jul 26, 2019
    Messages:
    5
    Likes Received:
    0
    Instead of calling the $IPactuelle parameter, it's send as is.
    Exemple : "New IP address is $IPactuelle" Instead of "New IP address is xxx.xxx.xxx.xxx"
     
  4. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    8,709
    Likes Received:
    736
    That is not related to Join though, right?
     
  5. PierreDurrr

    PierreDurrr New Member

    Joined:
    Jul 26, 2019
    Messages:
    5
    Likes Received:
    0
    Hum, don't really know... I've tried to adapt m'y script to pushbullet and it works, so it's probably that i made something wrong but can't figure what, or even if it's doable with Join
     
  6. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    8,709
    Likes Received:
    736
    How are you doing it with Pushbullet? That variable is not part of Join, it's something that you send to Join. Join doesn't interact with it at all :) Join just receives values and pushes it to your devices.
     
  7. PierreDurrr

    PierreDurrr New Member

    Joined:
    Jul 26, 2019
    Messages:
    5
    Likes Received:
    0
    Here is my pushbullet script

    #!/bin/bash

    # On rapatrie http://checkip.dyndns.com/ dans le fichier index.html
    wget http://checkip.dyndns.com/ -O /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/index.html

    # On extrait l'adresse IP du fichier index.html et on la place dans le fichier IPactuelle.txt
    cat /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/index.html | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' > /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/IPactuelle.txt

    # On stocke l'IP contenue dans le fichier IPactuelle.txt dans la variable $IPactuelle
    IPactuelle=$(cat /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/IPactuelle.txt)

    # On stocke l'IP contenue dans le fichier IPenregistree.txt dans la variable $IPenregistree
    IPenregistree=$(cat /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/IPenregistree.txt)

    # Si les variables $IPactuelle et $IPenregistree sont différentes et si $IPactuelle n'est pas vide
    if [ "$IPactuelle" != "$IPenregistree" ] && [ "$IPactuelle" != "" ]
    then
    # On remplace le fichier IPenregistree.txt par IPactuelle.txt
    cp /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/IPactuelle.txt /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/IPenregistree.txt

    # On envoie la notification Pushbullet
    curl -s -u api_key_here https://api.pushbullet.com/v2/pushes -d type=note -d title="Maison - Changement IP" -d body="L'adresse IP publique de la maison vient de changer. Penser à mettre à jour les paramètres VPN.

    Nouvelle adresse : $IPactuelle" > /dev/null


    fi

    # On supprime le fichier index.html
    rm /volume2/homes/PierreDurrr/Scripts_Serveur/_Output/notify-change-IP/index.html
     
  8. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    8,709
    Likes Received:
    736
    Thanks. How are you doing it with Join?
     
  9. PierreDurrr

    PierreDurrr New Member

    Joined:
    Jul 26, 2019
    Messages:
    5
    Likes Received:
    0
    Join script is in first post, at the curl command
     
  10. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    8,709
    Likes Received:
    736
    Oh I see. Seems that in the Join URL you didn't use $IPactuelle. Can you check the URL again :)
     

Share This Page