How can I send mobile text message from terminal?

84,182

Solution 1

SMS Texting from Terminal / Shell / Bash

For the following steps open a terminal prompt aka "Command Line Interface" or "CLI". In most Linux distributions do this using Ctrl+Alt+T

textbelt.com to send text from bash

I found a reddit article: Send an SMS Text Message from the Command Line with this Bash / Terminal command you can use:

curl -X POST https://textbelt.com/text \
   --data-urlencode phone='7801234567' \
   --data-urlencode message='Find Your Phone!' \
   -d key=textbelt

Replace 7801234567 with your phone number. If you are texting an international phone number (outside Canada / USA) follow these instructions.

Note: The software replaces "Find Your Phone!" with a message that you need to purchase a key to use a custom message. But the software still insists you must provide a message that gets overwritten.


Other reasons for sending SMS Text Message from Bash

Finding my smartphone was an unusual need to send an SMS text message from Bash. You might have a few people that should be texted when:

  • Disks are about to fail (or other hardware errors occurred)
  • Disk space utilization exceeds threshold, for example 90%
  • RAM is full and swap is being used heavily
  • Web server is experiencing external attacks
  • A user had too many invalid sign-ons and account is deactivated
  • A specific job has been run which effects key processes
  • A door badge reader monitors a certain door being unlocked

textbelt.com is Free for one text per day

Only one free SMS message a day can be sent by a given sender. Here is an example of the first and second attempts on one day:

$ find-phone # bash script with above command
{"success":true,"textId":"168141545572031481","quotaRemaining":0}

$ find-phone
{"success":false,"error":"Only one test text message is allowed per day.","quotaRemaining":0}

Note: You maybe able to reset your router's IP address for more than one text per day but I haven't tested this yet.

You can use prepaid unlimited texts. There are many SMS gateway services available. Pricing at above vendor link varies from $0.03 to $0.15 per text. This is for reference and not an endorsement nor recommendation. Please do your homework and search for reputable pay-for-service vendors at best prices.


Create Bash Script

You could create a bash script called sms containing:

#!/bin/bash
curl -X POST https://textbelt.com/text --data-urlencode phone='$1' --data-urlencode message='$2' -d key=textbelt
  • Send SMS message using sms 7801234567 "Hello World"
  • Thank you Fabby for testing this from the EU and confirming it works there.

Send Email to carrier of the smartphone with SMS Text Message

For the following all you need is a web browser like FireFox, Internet Explorer or Chrome. No need to dive into the "bowels of bash" or limit yourself to one free text per day.

Many carriers allow you to send SMS Text Message to a smartphone by addressing an email to phone_number@mobile_provider_name.com.

Phone Number look up to get carrier's website address

To get the provider's website address using the phone number go to: https://freecarrierlookup.com/. Imagine we entered the phone number: 7801234567:

Fee Carrier Lookup.png

We are told the email address to use is [email protected]. Now send an email to this address and your phone will sound with a notification.

Of course if you have your smartphone configured to sound with a notification when email arrives you can simply email your phone in the first place!

CLI interface for sending email address

In Ask Ubuntu there are many questions and answers on how to send email using bash. I'm using ssmtp (Secure Simple Mail Transport Protocol) for my cron daily backups: Backup Linux configuration, scripts and documents to Gmail

Although this setup is for one user, you can create a file with multiple users to text messages to:

Name         Email Address
Tiny Tim     [email protected]
Mrs. Clause  [email protected]
Bad Elf      [email protected]

Then in your bash code something like this:

ssmtp [email protected] < mail.txt

Where mail.txt looks like this:

Cc: admin@our_company.com
Subject: Nightly Database Update FAILED
From: root@our_company.com
Content-Type: text/html; charset="utf8"


<html>
<body>
<div style="
    background-color:
    #abcdef; width: 300px;
    height: 300px;
    ">
</div>
Nightly database update failed at procedure: AP005.
</body>
</html>

There are many ways of sending email from bash. This is just one example. The important thing is the email address contains the smartphone number followed by the smartphone provider's web address

Solution 2

This answer is not for command line as I can't find a command line solution for Google.

If you have an Android phone and don't want to use the command line, you can go to https://www.google.com/android/find in a web browser and ring your phone from there regardless of mute, vibrate or being connected to a Bluetooth headset. There is no extra software required on your phone either. This can also be done as many times as you want in a day.

Solution 3

Phone call from the browser, using Google Hangouts

You can also locate your phone by calling it, even if you don't have a landline.

Prerequisite: a Google account

Note: Only most calls to the US and Canada are free. See https://www.google.com/voice/b/0/rates?p=hangout for rates.

  1. Go to hangouts.google.com
  2. Click the "Phone call" button:
    button screenshot
  3. Click "New conversation":
    button screenshot
  4. Enter your phone number:
    number entry box screenshot
  5. Click "Call":
    call button screenshot
Share:
84,182

Related videos on Youtube

WinEunuuchs2Unix
Author by

WinEunuuchs2Unix

Software development is my main hobby. Check out the new websites created in October 2021: www.pippim.com and pippim.github.io

Updated on September 18, 2022

Comments

  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 1 year

    I've just lost my phone. I know it's here in my house cause I used it last night and my bluetooth speakers will connect to it this morning.

    How can I text my phone using bash? Then the phone notification will sound and I can find my phone.

    Note: I asked for a bash solution because it's simpler than installing and configuring a GUI. Also I am more comfortable working in bash than python, HTML, or java, etc. Finally a bash solution works in Windows 10 when you use the Windows Subsystem for Linux (WSL).

    Note 2: Reply to comments:

    • I don't have a landline so I can't simply call my smartphone.
    • It was 6 am on Sunday morning when I lost my phone. People I could email to call my phone were sleeping. I was unsure of the battery charge level and if it died, I could never text it.
    • A few weeks previously I had turned off email sound notifications on my smartphone so I couldn't email myself.
    • I don't have skype or any VOIP service providers

    After 30 minutes I did find the smartphone by texting it using the answer I posted below. It was hidden underneath 4" high-from-floor furniture shelf in the living-room...

    • Terrance
      Terrance over 5 years
      If I read this correctly, you are asking for the equivalent of the Find My Phone service that will ring your phone regardless of volume, vibrate mode, bluetooth headphone, etc connected that make the phone silent. I know that Google has the one for android that you can do, but I am not aware of command line form of it. If I can figure it out it is unlimited for use. Same thing for Apple.
    • Terrance
      Terrance over 5 years
      There is no software to install on the Android one. You just go to google.com/android/find
    • Michael Frank
      Michael Frank over 5 years
      "Okay Google!" listening intensifies....
    • cregox
      cregox over 2 years
      this must be the worst case of upvoting a terrible question that i ever seen on sen! 🤣 just because you can send an SMS using such complex means that barely work in the USA, doesn't mean you are doing it in the linux way at all... then again, i must be extra grumpy today for some reason. in any case, i do need a good solution for this question! one that only uses bash and a cellphone with linux, and no 3rd parties or internet. please let me know if you, dear kind reader, do find a solution before i come back here. cheers! 😘
  • Kevin
    Kevin over 5 years
    There are also email addresses you can send to that the phone company will forward to your phone as a text.
  • Kevin
    Kevin over 5 years
    I won’t be at a computer to test for 12+ hours, but I’ve definitely sent emails from the command line before. It may take some configuration (username/password) to get it working for gmail specifically though.
  • sudodus
    sudodus over 5 years
    @Kevin, It is also a good idea to send an SMS from gmail in order to find a phone, even if it is via a graphical user interface (and a graphical desktop environment).
  • sudodus
    sudodus over 5 years
    Skype can send an SMS or a regular voice phone-call (which will make the phone make sounds for a longer time). It costs money, but not too much. Maybe they won't charge for a phone-call, it you don't answer (after finding the phone) ;-)
  • TonyB
    TonyB over 5 years
    Sending TEXT via email works. However, you need to know the carrier your text message recipient uses. Currently, you can determine that via freecarrierlookup.com You will also get an email address to use for sending an SMS or MMS message. i.e.: [email protected]... after getting the email address for sending text, then use whatever email methodology you like, from command line mail, to gmail, to thunderbird, etc. to format the text message and send it.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 5 years
    I see $0.00 next to the phone number to call. Can you elaborate on cost to use this service?
  • PerlDuck
    PerlDuck over 5 years
    I know it's beyond the scope of this Q&A but for sending alerts for full disks/RAM or any other failures to dedicated users I would not rely on a service that sends SMS once a day but attach a modem with a SIM card instead. In Germany (Europe?) the CEP CT63 is quite popular.
  • Fabby
    Fabby over 5 years
    It works internationally as well, but the only message you get is "to customize this message, get a key"
  • sudodus
    sudodus over 5 years
    Does not work in my country without money on their account.
  • Nonny Moose
    Nonny Moose over 5 years
    @WinEunuuchs2Unix So sorry! I forgot that Google Hangouts charges for calls outside of the US and Canada. I've updated my answer accordingly.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 5 years
    @NonnyMoose Thanks for updating. I already upvoted your answer before my comment.
  • Mast
    Mast over 5 years
    "Most if not all carriers" That's quite localized information. Around here (Netherlands), it doesn't appear to work.
  • kasperd
    kasperd over 5 years
    If the limitation is one SMS per day per IP address, then that's not much of a limitation. I have 313 trillion IP addresses on my LAN.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 5 years
    @Mast I've changed "Most if not all carriers" to "Many carriers". It may have been better to say "Most USA/Canada providers". If the carrier name lookup doesn't work, most people know their smartphone provider and could google search the website address.
  • mike3996
    mike3996 over 5 years
    What's that HTML doing in an email?
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 5 years
    @progo That's from the article I linked. The way I send email from bash is linked above that link. The method I use is: echo -e "to: $EmailAddr\nsubject: $FileName\n" | (cat - && uuencode "$FileName" "$FileName") | ssmtp "$EmailAddr".
  • Pryftan
    Pryftan almost 5 years
    @PerlDuck Though to be fair depending on how you set it up it could work well. I’m part of a MUD and years ago when the server owner (and founder - I helped him in programming and various other things and still do though not nearly as much as I used to) was on holiday and a OOM problem caused a panic. What could be done though? Well he set up a script that probes the server every so often (probably regularly), did not get a response and so sent a message to the person watching the house. They did a hard reboot and all was okay :) But I see your point of course too just not the only way. :)
  • WinEunuuchs2Unix
    WinEunuuchs2Unix almost 5 years
    @PerlDuck This solution works for home user like myself sending text message daily for free. For a business you can purchase text messages for 40 cents each and send unlimited times per day which is cheaper than new hardware and cell number.
  • PerlDuck
    PerlDuck almost 5 years
    @WinEunuuchs2Unix Of course you are right. Recently I started to use Pushover for such notifications. The account is free and sending notifications is easy (e.g. curl). The App to receive them has a 7-day-free-trial period and then costs 5 $ once.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix almost 5 years
    @PerlDuck I took a quick peek at your link. Do you think that's worth posting as an answer here?
  • PerlDuck
    PerlDuck almost 5 years
    @WinEunuuchs2Unix I don't think so. Pushover is a great tool, but it is not a classic text messaging tool. You need a dedicated client on the receiving end.