Sending SMS from commandline / adb

1,223 views
Skip to first unread message

speeduploop

unread,
May 4, 2019, 2:04:40 PM5/4/19
to comp.mobile.nokia.8110
Hi people!

Some time ago a few people asked about sending SMS from commandline...

So I wrote a little script ;)

sendsms
#!/system/bin/sh

if [ "$#" -ne 2 ]; then
  echo
  echo "----------- sendsms by speeduploop -----------"
  echo "- simple script to send sms from commandline -"
  echo "----------------------------------------------"
  echo "usage   : sendsms <number> <message>"
  echo "examples:"
  echo -e "  sendsms 01239878765 'hallo welt!!!'"
  echo -e "  sendsms '01239878765' hallo\ welt!!!"
  echo -e "  sendsms '01239878765' 'hallo welt!!!'"
  echo -e "  sendsms +491239878765 'hallo\\\nwelt!!!'"
  echo
  exit 1
fi

echo -ne "\e" > /dev/smd8
echo -ne "at+cmgf=1\r\n" > /dev/smd8
echo -ne "at+cmgs=\"$1\"\r\n" > /dev/smd8
echo -ne "$2\x1a" > /dev/smd8
sleep 1
echo -ne "at+cmgf=0\r\n" > /dev/smd8

Without arguments it shows the usage-help...
shell@Nokia 8110 4G:/data/opt/bin $ ./sendsms                                  

----------- sendsms by speeduploop -----------
- simple script to send sms from commandline -
----------------------------------------------
usage   : sendsms <number> <message>
examples:
  sendsms 01239878765 'hallo welt!!!'
  sendsms '01239878765' hallo\ welt!!!
  sendsms '01239878765' 'hallo welt!!!'
  sendsms +491239878765 'hallo\nwelt!!!'


But yes... it usually needs root.

If you don't want to use root every time to send a SMS you can also lower the permissions of the device-node:
chmod 555 /dev/smd8

You need this once after every reboot - so probably in your init-file.
(on a bootstrapped device /data/opt/init)

After that you can use the script without root permissions -- even over adb from a PC!

--> on GerdaOS, stock-firmware with patched adbd or via a telnet-backdoor it will just work...

have fun!
speeduploop
sendsms

perry

unread,
May 5, 2019, 3:50:16 AM5/5/19
to comp.mobile.nokia.8110
thank you speeduploop!

the file has to be uploaded ?

speeduploop

unread,
May 5, 2019, 3:55:13 AM5/5/19
to comp.mobile.nokia.8110
Yes - it's a script to run directly on the device.

--> you can push it either to /data/local/tmp for temp-use or to /data/opt if you have bootstrapped...
(don't forget exec-permissions --> 'chmod +x sendsms')

Or adapt the last 6 lines of code and integrate it in own scripts..

perry

unread,
May 5, 2019, 4:01:48 AM5/5/19
to comp.mobile.nokia.8110
/data/opt do not exist
root@Nokia 8110:/data     mkdir opt

it is right ?

speeduploop

unread,
May 5, 2019, 4:05:16 AM5/5/19
to comp.mobile.nokia.8110
yes... (my bootstrapon-script uses this by default to be able to set an additional init-script...)

mkdir -p /data/opt
chmod
777 /data/opt
the second line allows that you can easily push/pull with adb...
--> I also have /data/opt/bin ;)

perry

unread,
May 5, 2019, 4:08:26 AM5/5/19
to comp.mobile.nokia.8110
I'am on gerdaOs 
is the chmod 777 /data/opt necessary ?

speeduploop

unread,
May 5, 2019, 4:10:18 AM5/5/19
to comp.mobile.nokia.8110
IIRC adb on GerdaOS is patched to 'root-only'... so no.
The chmod is only needed to allow 'normal' adb to access it.

perry

unread,
May 5, 2019, 4:13:32 AM5/5/19
to comp.mobile.nokia.8110
/system/bin/sh: sendsms: not found

how the system know the file is in /data/opt/ ?

speeduploop

unread,
May 5, 2019, 4:17:31 AM5/5/19
to comp.mobile.nokia.8110
it doesn't unless you tell it... like usual.

Just use full path or move it to /system/bin.
(I usually put binaries/scripts I use often in /system/bin -- or use full path for things I don't use often)

perry

unread,
May 5, 2019, 4:20:51 AM5/5/19
to comp.mobile.nokia.8110
like this:
data/opt/sendsms sendsms 0049xxxxx6215 'hello world'

speeduploop

unread,
May 5, 2019, 4:24:11 AM5/5/19
to comp.mobile.nokia.8110
If it's in /data/opt then only one 'sendsms'...
/data/opt/sendsms 0049xxxxx6215 'hello world'

or even - from a PC:
adb shell /data/opt/sendsms 0049xxxxx6215 'hello world'

perry

unread,
May 5, 2019, 4:28:28 AM5/5/19
to comp.mobile.nokia.8110
oh yes! thanks.

speeduploop

unread,
May 5, 2019, 4:32:07 AM5/5/19
to comp.mobile.nokia.8110
One thing -- because I recognized a german number: there are some problems with non-ascii characters...
(so some german-umlauts will break it...)
Reply all
Reply to author
Forward
0 new messages