Skip to content

Instantly share code, notes, and snippets.

@PJUllrich
Last active October 23, 2023 20:49
Show Gist options
  • Save PJUllrich/e95baa0d718e55a6c67f85cd8e53dabe to your computer and use it in GitHub Desktop.
Save PJUllrich/e95baa0d718e55a6c67f85cd8e53dabe to your computer and use it in GitHub Desktop.
Bash script to send your IP via Pushover
#!/bin/bash
IP=`hostname -I | awk '{print $1}'`
MESSAGE="Pi ${HOSTNAME} fully booted. New IP: $IP"
TITLE="`whoami`@${HOSTNAME}"
APP_TOKEN="YOUR_APP_TOKEN_HERE"
USER_TOKEN="YOUR_USER_TOKEN_HERE"
wget https://api.pushover.net/1/messages.json --post-data="token=$APP_TOKEN&user=$USER_TOKEN&message=$MESSAGE&title=$TITLE" -qO- > /dev/null 2>&1 &
@PJUllrich
Copy link
Author

PJUllrich commented Mar 21, 2018

I use this to send the IP of my Raspberry Pi via Pushover to my phone so that I can connect via SSH to it.
To implement this, you have to do the following.

  1. Copy the gist to /home/YOUR_HOSTNAME/pushover.sh
  2. Make the gist executable with sudo chmod 755 /home/YOUR_HOSTNAME/pushover.sh
  3. Test it out with /home/YOUR_HOSTNAME/./pushover.sh
  4. Create a new service with
    1. sudo nano /etc/systemd/system/pushover-ip.service
    2. Copy the following into this file:
# Bash script sending IP upon reboot via Pushover
# /etc/systemd/system/pushover-ip.service

[Unit]
Description=Bash script to send IP upon reboot via Pushover
After=network-online.target
Wants=network-online.target

[Service]
User=pi
Group=pi
Type=forking
ExecStart=/home/YOUR_HOSTNAME/./pushover.sh
KillMode=process

[Install]
WantedBy=multi-user.target
  1. Disable IPv6 (otherwise systemd will execute your script before IPv4 is established)
    1. sudo nano /etc/sysctl.d/local.conf
    2. Copy the following into it: net.ipv6.conf.all.disable_ipv6=1
  2. Enable the network-online service: sudo systemctl enable systemd-networkd-wait-online.service
  3. Enable your service with sudo systemctl enable pushover-ip.service
  4. Test it out with: sudo shutdown -r now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment