dead-simple-notifications-with-pushover.md (5191B)
1 +++ 2 date = '2026-05-29T16:25:23-05:00' 3 draft = false 4 title = 'Dead Simple Notifications With Pushover and shell' 5 +++ 6 7 ## What is Pushover? 8 9 [Pushover](https://pushover.net/) is a notification service that makes it easy 10 to send real-time push notifications to the user's phone from scripts and 11 applications. Users can wrap the service in a few lines of shell and get 12 real-time notifications for automated tasks. Some examples include docker 13 container health checks, zpool status reports, and the outcome of shell 14 commands. 15 16 The service has native applications for iOS and Android, and a browser-based 17 client for desktop users. There is also a growing list of 18 [plugins](https://pushover.net/apps) for popular applications. Pushover 19 provides a simple [HTTP API](https://pushover.net/api). Used in combination 20 with the mobile application, users can build simple but effective notification 21 systems. 22 23 ### Cost and Limitations 24 25 The API allows up to 10,000 messages per month at no additional cost. Once 26 that limit is reached, blocks of additional capacity can be 27 [purchased](https://pushover.net/settings/upgrade). The mobile application 28 itself has a 30-day free trial, after which there is a one-time 29 [fee](https://pushover.net/pricing) of $5 per platform. 30 31 ## Getting Set Up 32 33 To get started the user will need a Pushover account. Head to 34 [pushover.net](https://pushover.net) and register. The user key is displayed 35 in the dashboard after registration and identifies where notifications will 36 be delivered. Install the mobile application and log in to start receiving 37 notifications on the phone. 38 39 Next the user needs to create an application. In the Pushover dashboard, click 40 "Create an Application/API Token". Give it a name like "server-scripts" 41 and submit the form. Pushover will generate an API token for that 42 application. 43 44 The user will need both the user key and the API token to send notifications. 45 Keep them somewhere safe. 46 47 ## Sending the First Notification 48 49 The simplest way to send a Pushover notification is with `curl`. This is a 50 good way to verify the credentials are working before integrating 51 notifications into scripts. 52 53 ```bash 54 curl -s \ 55 --form-string "token=YOUR_API_TOKEN" \ 56 --form-string "user=YOUR_USER_KEY" \ 57 --form-string "message=hello world" \ 58 https://api.pushover.net/1/messages.json 59 ``` 60 61 Replace `YOUR_API_TOKEN` and `YOUR_USER_KEY` with the values from the 62 Pushover dashboard. If everything is configured correctly, a notification 63 will appear on the phone within seconds. 64 65 Pushover's API supports a number of additional parameters, including message 66 title, priority, and sound. See the 67 [Pushover example code page](https://support.pushover.net/i44-example-code-and-pushover-libraries) 68 for examples in other languages. 69 70 ## Custom Notification Script 71 72 Rather than including the full `curl` command in every script, it can be wrapped 73 in a shell script of its own. This gives a reusable command that can be called 74 from any other script on the system. 75 76 ```bash 77 #!/bin/sh 78 79 PUSHOVER_TOKEN="YOUR_API_TOKEN" 80 PUSHOVER_USER="YOUR_USER_KEY" 81 82 /usr/bin/curl -s \ 83 --form-string "token=$PUSHOVER_TOKEN" \ 84 --form-string "user=$PUSHOVER_USER" \ 85 --form-string "title=$1" \ 86 --form-string "message=$2" \ 87 https://api.pushover.net/1/messages.json 88 ``` 89 90 Save this as `notify.sh` and make it executable: 91 92 ``` 93 chmod +x notify.sh 94 ``` 95 96 Place it in a directory that is in the path of the user that will be running 97 the notification scripts. On Linux `~/.local/bin` is a common choice. On 98 macOS `/usr/local/bin` is typical. Run `echo $PATH` to see what directories 99 are currently in the user's path. 100 101 With the script in place, sending a notification looks like this: 102 103 ``` 104 notify.sh "Testing notifications" "My first notification!" 105 ``` 106 107 Keep this script private and never commit it to a public repository. It 108 contains the user's Pushover credentials. 109 110 ## A Note on Sensitive Data 111 112 The API token and user key should be considered sensitive information. 113 For a script that lives only on the user's own machine and is never shared, 114 storing them directly in the script is acceptable. If the user plans to share 115 the script or commit it to a repository, use environment variables instead. 116 Set them in a private file like `~/.pushover`: 117 118 ```sh 119 export PUSHOVER_TOKEN="your-token" 120 export PUSHOVER_USER="your-user-key" 121 ``` 122 123 Source that file in the shell profile so the variables are available to 124 scripts: 125 126 ```sh 127 source ~/.pushover 128 ``` 129 130 Then remove the hardcoded values from the script and reference the variables 131 directly. The script is then safe to share publicly. 132 133 ## Practical Example 134 135 Call `notify.sh` at the end of any script to confirm it ran. Here it is 136 used with a simple backup: 137 138 ```bash 139 #!/bin/sh 140 141 rsync -a /home/$USER/ /mnt/backup/ 142 143 if [ $? -eq 0 ]; then 144 notify.sh "Backup" "Backup completed successfully" 145 else 146 notify.sh "Backup" "Backup failed" 147 fi 148 ``` 149 150 ## Conclusion 151 152 With a Pushover account and a small shell script, the user has a notification 153 system that works from anywhere a shell command can be run. Adding a 154 notification to an existing script is a simple process. This makes it easy 155 to stay informed about what is happening on the systems without having to 156 check manually.