Ajout du script freesms
Il permet de s'envoyer un sms sur son propre mobile
This commit is contained in:
parent
43b5624501
commit
6f8af2eaa1
89
sms/freesms
Executable file
89
sms/freesms
Executable file
@ -0,0 +1,89 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
function display_help() {
|
||||
echo "${0} Usage :"
|
||||
echo -e "\t-u --utilisateur\tSpecify the username"
|
||||
echo -e "\t-p --password\tSpecify the password"
|
||||
echo -e "\t-h or --help\tThis help"
|
||||
echo ""
|
||||
echo "Examples :"
|
||||
echo -e "\tSend \"My message\" to your mobile phone :"
|
||||
echo -e "\t\t${0} -u myuser -p mypassword My message"
|
||||
echo -e "\tSend content from STDIN to your mobile phone :"
|
||||
echo -e "\t\t${0} -u myuser -p mypassword -"
|
||||
}
|
||||
|
||||
GET_OPT=`getopt -o hu:p: --long help,utilisateur:,password: -n "${0} parameters" -- "${@}"`
|
||||
if [ ! "${?}" == "0" ] ; then
|
||||
display_help
|
||||
exit 1
|
||||
fi
|
||||
eval set -- "$GET_OPT"
|
||||
while true ; do
|
||||
case ${1} in
|
||||
-u|--utilisateur)
|
||||
NOM="${2}"
|
||||
shift 2
|
||||
;;
|
||||
-p|--password)
|
||||
PASS="${2}"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
display_help
|
||||
shift
|
||||
exit 0
|
||||
;;
|
||||
--)
|
||||
MESSAGE="`echo ${@} | sed 's|^-- ||g'`"
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
display_help >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "${NOM}" -o -z "${PASS}" ] ; then
|
||||
echo "You need to specify Username and Password" >&2
|
||||
display_help >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${MESSAGE}" == "-" ] ; then
|
||||
if [[ ! -t 0 ]]; then
|
||||
while read line ; do
|
||||
MESSAGE="${MESSAGE}%0D${line}"
|
||||
MESSAGE=`echo ${MESSAGE} | sed 's|^-%0D||g'`
|
||||
done < <(cat -)
|
||||
else
|
||||
echo "STDIN is empty" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "${MESSAGE}" ] ; then
|
||||
echo "You need to specify the message to send" >&2
|
||||
display_help >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
envoi=$(curl -i --insecure "https://smsapi.free-mobile.fr/sendmsg?user=${NOM}&pass=${PASS}&msg=${MESSAGE}" 2>&1)
|
||||
retour_HTTP=$(echo "${envoi}" | awk '/HTTP/ {print $2}')
|
||||
case $retour_HTTP in
|
||||
200)
|
||||
echo "Le message a été envoyé correctement"
|
||||
;;
|
||||
400)
|
||||
echo "le couple expéditeur/mot de passe est erroné, veuillez les vérifier dans le script";;
|
||||
402)
|
||||
echo "Trop de SMS ont été envoyés en trop peu de temps. Veuillez renouveler ultérieurement";;
|
||||
403)
|
||||
echo "Le service n’est pas activé sur l’espace abonné. Veuillez l'activer S.V.P";;
|
||||
500)
|
||||
echo " Erreur côté serveur. Veuillez réessayez ultérieurement."
|
||||
esac
|
||||
exit 0
|
Loading…
Reference in New Issue
Block a user