How to push/send message to iOS and Android from Linux CLI

How to push or send message to iOS and Android
One of the essential tasks for developers and sysadmin is to get an alert notification about failed services or running out of disk space and other critical failures. Let us see how to send or push a direct message to a mobile device powered by Apple iOS or Google Android phone.

How to push/send message to iOS and Android in real time

We can use the AWS SNS push notification service to send an alert directly to an application on a mobile device. However, today I am going to use straightforward app service called Pushover. It is a simple app to get real-time notifications on Android, iPhone, iPad, and Desktop, including Android Wear and Apple Watch.

Why send notifications?

As an independent developer and Linux sysadmin, I needed a simple way to get a notification for my side projects using API. I can get a notification for failed backups or my Nginx service overloaded due to problems or MySQL read-only replica running out of sync. My search ended with Pushover. However, it is not a free service. To use Pushover for yourself or a small group, it’s just a USD $5 one-time purchase on each platform. You can send 7,500 messages per month, which is more than sufficient for my needs. They also have an option to send messages for a group of developers and IT teams. My criteria were simple:

  1. I needed support for my Perl, Python, and bash/shell scripts.
  2. Must push notification to iPhone.
  3. Must not be very expensive.

The Pushover service seems to fit all my requirements. Enough talk, let’s get our hands-on dirty with some examples.

Step 1 – Sign up for Pushover

First download Pushover device clients:

  • Android version
  • iOS (iPhone, iPod Touch, and iPad) version

Make sure you subscribe to service or get a seven-day trial account. Once logged in, register your cli application, set its name, and get an API token in return.

Step 2 – Create a shell script wrapper API script

Create a new shell script as follows:
$ vi ~/bin/
Append the code:

#!/usr/bin/env bash
# push/send message ios and android using API from my Linux box
# Set API stuff 
# Bash function to push notification to my iPhone 
# yes you can push/send message android too using the same function
	local t="${1:cli-app}"
	local m="$2"
	[[ "$m" != "" ]] && curl -s \
	  --form-string "token=${_token}" \
	  --form-string "user=${_user}" \
	  --form-string "title=$t" \
	  --form-string "message=$m" \

Next, use the source command:
$ source ~/bin/
Test it:
$ push_to_mobile "bash-notification" "This is a test. Job foo failed on $HOSTNAME @ $(date)"
Immediately I will get a notification on my phone:

Shell sent push notifications to my iPhone from Linux command line

How to Send both email and push notifications to your phone from script

We can simple use the sendmail command or mail command as follows from our shell scripts:

#!/usr/bin/bin bash
# Wrapper by Vivek Gite under GPL v2.0+
# ------------------------------------------------------- 
# Set email stuff
# warning: must need pre-configured smtpd such as sendmail/postfix
subject="rsnapshot backup job failed at $HOSTNAME"
# start daily backup and set log to ${log_file}
# all reports created by script including ERROR
/usr/bin/rsnapshot daily 2>&1 | /root/bin/ > "${log_file}"
# Catch errors 
alogs="$(egrep -w '^ERROR:|ERROR' $log_file)"
# If failed, notify using both email and push message to my phone
if [ $status -ne 0 ] ||  [ "$alogs" != "" ];
   mail -A "$log_file" -s "$subject" -r "$from" "$to" <<< "Backup script failed with error. Check attached log file" # # Push/send message to iOS and Android using Pushover API too # source ~/bin/ push_to_mobile "backup-script" "$subject. See $to email for detailed failed log." >/dev/null

See the following tutorials for more information about sending emails from the CLI:


So far, Pushover service and app worked great for me. I can easily send/push messages to iOS and Android devices using shell/Perl/Python scripts. Check out all other suggestions on my Twitter thread:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 9 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
9 comments… add one
  • Tony Jul 15, 2020 @ 11:28

    We are using Pushover too and I loved it. Saved my time and headache many times.

    • Tim Jul 15, 2020 @ 12:33

      Is it monthly fees? Are you using with Android 10?

      • DJ Tux 🐘 Sep 4, 2020 @ 13:41

        No one time fee

  • Shree Aug 4, 2020 @ 0:35

    Is there any free software for android? I can’t afford paid option for my home project.

  • Mike Sep 1, 2020 @ 18:00

    I’m using Telegram bot, more simple and free. No need install other application and make new account on 3rd party.

  • drew Jan 30, 2021 @ 2:17

    seems like the names of things changed a little.

    In pushover you have to create a “Your Application” at the bottom of the main page. That will give you your API/Token Key, which is _token above.

    Then your _user is on the main page, called “Your user key” which is also a bunch of characters strung together, similar to that different API.

  • gary Feb 19, 2021 @ 16:33

    Thanks for the script, works great.
    Question: is it possible to output something like the command: $ ls
    > send to pushover?

    • 🐧 Vivek Gite Feb 19, 2021 @ 17:38

      yes, something like:

      ls > /tmp/output.txt
      push_to_mobile "message 
      $(cat /tmp/output.txt)
      rm /tmp/output.txt

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum