diff --git a/.gitignore b/.gitignore index 16a1b3d..bc5c0bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -repos -exclude notify -github \ No newline at end of file +sms +smsto \ No newline at end of file diff --git a/getPrice.sh b/getPrice.sh index 135d8bf..16efcea 100755 --- a/getPrice.sh +++ b/getPrice.sh @@ -23,6 +23,9 @@ VDMHOME=~/ # load notify . "$DIR/notify.sh" +# load sms +. "$DIR/sms.sh" + # main function function main () { echoTweak "Getting the current price of $Currency in $Target" @@ -48,6 +51,8 @@ function main () { fi # show linux messages if any were loaded showLinuxMessage + # send SMS messages if any were loaded + sendSMSMessage } function getTarget() { @@ -136,6 +141,8 @@ function sendMessage () { sendTelegram "$message" # set Linux messages setLinuxMessage "$message" + # set SMS messages + setSMSMessage "$message" } # check if we already showed the message today @@ -202,6 +209,8 @@ AboveValue=0 Telegram=0 linuxMessages=() LinuxNotice=0 +SMSMessages=() +SMS=0 API="https://cex.io/api/last_price/" VDMHOME=~/ @@ -229,6 +238,7 @@ Getting Coin Value in Fiat Currency at set price -b Send Notice below target value once a day -a Send Notice above target value once a day (default) -n Send A Telegram Notice aswell (always shows comandline Notice) + -m Send A SMS Notice aswell (always shows comandline Notice) -l Show A Linux Notice aswell (always shows comandline Notice) EOF @@ -240,7 +250,7 @@ exit 1 # http://mywiki.wooledge.org/BashFAQ/035 # http://wiki.bash-hackers.org/howto/getopts_tutorial -while getopts ":c:t:s:v:A:B:b :a :n :l :" opt; do +while getopts ":c:t:s:v:A:B:b :a :n :m :l :" opt; do case $opt in c) Currency=$OPTARG @@ -269,6 +279,9 @@ while getopts ":c:t:s:v:A:B:b :a :n :l :" opt; do n) Telegram=1 ;; + m) + SMS=1 + ;; l) LinuxNotice=1 ;; @@ -319,6 +332,25 @@ function showLinuxMessage () { fi } +# set sms messages +function setSMSMessage () { + # check if we should send sms messages + if (( "$SMS" == 1 && "$show" == 1 )); + then + SMSMessages+=("$1") + fi +} + +# send sms messages +function sendSMSMessage () { + # check if we have messages to send + if [ ${#SMSMessages[@]} -gt 0 ]; then + IFS=$'\n' + messages="${SMSMessages[*]}" + smsMe "${messages}" + fi +} + # send Telegram function sendTelegram () { # check if we should send telegram diff --git a/notify.sh b/notify.sh index 04cc6f5..2f94506 100755 --- a/notify.sh +++ b/notify.sh @@ -21,14 +21,21 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Telegram notify function notifyMe() { + # check if notify is set + if [ ! -f "$DIR/notify" ] + then + echo "Please set the details for Telegram found in notify.txt" + exit 1 + fi # get first line - NOTIFY=$(head -n 1 "$DIR/notify") + local NOTIFY=$(head -n 1 "$DIR/notify") # get the keys - keys=( $NOTIFY ) + IFS=$' ' + local keys=( $NOTIFY ) # set chatid & token - chatid="${keys[0]}" - token="${keys[1]}" - default_message="notify!" + local chatid="${keys[0]}" + local token="${keys[1]}" + local default_message="notify!" if [ -z "$@" ] then diff --git a/sms.sh b/sms.sh new file mode 100644 index 0000000..ed3c8b2 --- /dev/null +++ b/sms.sh @@ -0,0 +1,50 @@ +#!/bin/bash +#/--------------------------------------------------------------------------------------------------------| www.vdm.io |------/ +# __ __ _ _____ _ _ __ __ _ _ _ +# \ \ / / | | | __ \ | | | | | \/ | | | | | | | +# \ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| | +# \ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` | +# \ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| | +# \/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_| +# | | +# |_| +#/-------------------------------------------------------------------------------------------------------------------------------/ +# +# @author Llewellyn van der Merwe +# @copyright Copyright (C) 2016. All Rights Reserved +# @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html +# +#/-----------------------------------------------------------------------------------------------------------------------------/ + +# get script path +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# clickatell sms HTTP +function smsMe() { + # check if sms details are set + if [ ! -f "$DIR/sms" ] + then + echo "Please set the details for clickatell found in sms.txt" + exit 1 + fi + # check if phone numbers are set + if [ ! -f "$DIR/smsto" ] + then + echo "Please set the phone numbers as found in smsto.txt" + exit 1 + fi + # set Args + local message="$1" + # get first line + local SMSd=$(head -n 1 "$DIR/sms") + local to=$(head -n 1 "$DIR/smsto") + # get the keys + IFS=$' ' + local keyss=( $SMSd ) + # set user, password & api_id + local username="${keyss[0]}" + local password="${keyss[1]}" + local api_id="${keyss[2]}" + # send the sms's + curl -s --data "user=${username}&password=${password}&api_id=${api_id}&to=${to}&text=${message}" "https://api.clickatell.com/http/sendmsg" +} diff --git a/sms.txt b/sms.txt new file mode 100644 index 0000000..fbe9ae1 --- /dev/null +++ b/sms.txt @@ -0,0 +1,3 @@ +# here you add the sms username, password and API id (example) +# username password api_id +# James xxxxxx 0000001 (remove this note and remove .txt from the file name ;) diff --git a/smsto.txt b/smsto.txt new file mode 100644 index 0000000..3bb44fd --- /dev/null +++ b/smsto.txt @@ -0,0 +1,3 @@ +# here you add all then numbers to sms comma separated(example) +# number,number,number +# 264810000000,264811111111,264812222222,264812222222 (remove this note and remove .txt from the file name ;)