From 8aaf901c192fe7c0630a459822eb1a4cb146b1ca Mon Sep 17 00:00:00 2001 From: C-Duv Date: Fri, 13 Jun 2014 00:21:17 +0200 Subject: [PATCH] Avoids using $NEWLINE_CHAR variable in configuration To simplify and improve readability of configuration options, use of standard newline character is preferred over $NEWLINE_CHAR. This commit uses \n in configuration options instead of $NEWLINE_CHAR and adds a final \n to $NEWLINE_CHAR conversion step just prior to sending. --- send-notification.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/send-notification.sh b/send-notification.sh index b139f86..6dcc915 100644 --- a/send-notification.sh +++ b/send-notification.sh @@ -39,10 +39,13 @@ USER_LOGIN="1234567890" API_KEY="s0me5eCre74p1K3y" # Texte qui sera ajouté AVANT chaque message envoyé -MESSAGE_HEADER="Notification :${NEWLINE_CHAR}" +MESSAGE_HEADER="Notification : +" # Texte qui sera ajouté APRÈS chaque message envoyé -MESSAGE_FOOTER="${NEWLINE_CHAR}--${NEWLINE_CHAR}Le serveur de la maison" +MESSAGE_FOOTER=" +-- +Le serveur de la maison" ## @@ -55,9 +58,9 @@ if [ "$1" ]; then # Message en tant qu'argument de la ligne de commande else # Message lu de STDIN while read line do - MESSAGE_TO_SEND="$MESSAGE_TO_SEND$line$NEWLINE_CHAR" + MESSAGE_TO_SEND="$MESSAGE_TO_SEND$line\n" done - MESSAGE_TO_SEND=$(echo $MESSAGE_TO_SEND | sed 's/'$NEWLINE_CHAR'$//') # Retire le dernier saut de ligne + MESSAGE_TO_SEND=$(echo $MESSAGE_TO_SEND | sed 's/\n$//') # Retire le dernier saut de ligne fi FINAL_MESSAGE_TO_SEND="$MESSAGE_HEADER$MESSAGE_TO_SEND$MESSAGE_FOOTER" # Assemble header, message et footer @@ -69,6 +72,11 @@ FINAL_MESSAGE_TO_SEND="$MESSAGE_HEADER$MESSAGE_TO_SEND$MESSAGE_FOOTER" # Assembl # echo "Will send the following to $USER_LOGIN:" #DEBUG # echo "$FINAL_MESSAGE_TO_SEND" #DEBUG +# Converts newlines to $NEWLINE_CHAR +FINAL_MESSAGE_TO_SEND=$(echo -n "$FINAL_MESSAGE_TO_SEND" | sed '{:q;N;s/\n/'$NEWLINE_CHAR'/g;t q}') +# echo "Newline encoded message:" #DEBUG +# echo "$FINAL_MESSAGE_TO_SEND" #DEBUG + # --insecure : Certificat de $SMSAPI_BASEURL ne fourni pas d'informations sur son propriétaire # --write-out "%{http_code}" --silent --output /dev/null : Renvoi le code réponse HTTP uniquement HTTP_STATUS_CODE=$(curl --insecure --get "$SMSAPI_BASEURL/$SMSAPI_SEND_ACTION" --data "user=$USER_LOGIN" --data "pass=$API_KEY" --data "msg=$FINAL_MESSAGE_TO_SEND" --write-out "%{http_code}" --silent --output /dev/null)