I have a couple of scripts running on my Linux PC and ssh to the phone to read the latest SMS and parse the OTP for the main services I use.
Here’s how I do it
Main script, that executes sms reader (see below) on phone and parses SMS text on PC:
#!/bin/bash
MSG=$(cat ~/bin/readOtpFromXA2.sh | ssh xa2usb)
if echo $MSG | grep -q "^Your PingID authentication code is:"
then
echo "got PingID"
OTP=$(echo "${MSG}" | rev | cut -d ' ' -f 1 | rev)
elif echo $MSG | grep -q "^Your OTP Code:"
then
echo "got Entitlement OTP"
OTP=$(echo "${MSG}" | cut -d ' ' -f 4)
elif echo $MSG | grep -q "Verwenden Sie diesen Code fĂĽr die ĂśberprĂĽfung von Microsoft.$"
then
echo "Microsoft OTP"
OTP=$(echo $MSG | head -c 6)
elif echo $MSG | grep -q "Use this code for Microsoft verification$"
then
echo "Microsoft OTP"
OTP=$(echo $MSG | head -c 6)
elif echo $MSG | grep "^Use verification code" | grep -q "for Microsoft authentication."
then
echo "Microsoft OTP"
OTP=$(echo $MSG | cut -d ' ' -f 4 )
elif echo $MSG | grep "^Verwenden Sie den PrĂĽfcode" | grep -q "die Microsoft-Authentifizierung"
then
echo "Microsoft OTP"
OTP=$(echo $MSG | cut -d '"' -f 2 )
else
kdialog --passivepopup "Unknown message pattern: \n$MSG"
exit
fi
echo "${OTP}" | xclip -selection c \
&& kdialog --passivepopup "OTP: $(xclip -o -selection c)" 3
Extracting latest SMS ~/bin/readOtopFromXA2.sh
:
#! /usr/bin/env bash
MSG=$(sqlite3 /home/nemo/.local/share/commhistory/commhistory.db "select freetext from events order by id desc limit 1;")
MSGID=$(sqlite3 /home/nemo/.local/share/commhistory/commhistory.db "select id from events order by id desc limit 1;")
sqlite3 /home/nemo/.local/share/commhistory/commhistory.db "update events set isRead = 1 where id = $MSGID;"
echo $MSG