SHELL (command)
Runs command and returns its output
context outgoing_calls_mobile { _89XXXXXXXXX => { Noop( file_conf outgoing_calls.ael context outcoming_calls_mobile); Noop( ${CALLERID(num)} ${EXTEN}); Set(mobile_operator_info=${SHELL(/etc/asterisk/scripts/operatorIF.sh ${EXTEN:1} ${CALLERID(num)})}); // , "error" if ("${mobile_operator_trunk_cid}" = "ERROR") { Gosub(error,s,1(${CALLERID(num)},${EXTEN})); }; // CUT, Set(mobile_operator_name=${CUT(mobile_operator_info,\,,1)}); Set(mobile_operator_id_region=${CUT(mobile_operator_info,\,,2)}); Set(mobile_operator_region=${CUT(mobile_operator_info,\,,3)}); Set(mobile_operator_region_id=${CUT(mobile_operator_info,\,,4)}); // : // mobile_operator_name - // mobile_operator_id_region - id // mobile_operator_region - // mobile_operator_region_id - id - // , // // , , . Dial(SIP/${mobile_operator_name}/${EXTEN:1},60,); // Gosub(test_dial,s,1(${DIALSTATUS},${exten})); Hangup(); }; };
http://www.megafon.ru/api/mfn/info?msisdn=79XXXXXXXXX
{"operator":"","operator_id":99,"region":" .","region_id":56}
#!/bin/bash sql='mysql -uprovisioning -pxkYyNFuyc3nEKsFj -Dasterisk -e' # , lifetime=30 # , # , 30 , . array_operator_old=($($sql "SELECT operator,operator_id,region,region_id FROM operators WHERE to_phon_nomber like '$1' \ and data >DATE_ADD(NOW(), INTERVAL -$lifetime DAY) limit 1"| awk 'NR>1')) # , , . if [ -n "${array_operator_old[1]}" ] then operator_old=${array_operator_old[0]} operator_id_old=${array_operator_old[1]} region_old=${array_operator_old[2]} region_id_old=${array_operator_old[3]} echo -n $operator_old,$operator_id_old,$region_old,$region_id_old exit 0 fi # , : array_operator=($(curl -s http://www.megafon.ru/api/mfn/info?msisdn=$1|tr -d '"{}'|tr -s ' ' '_'|tr -s ',' '\t')) # , , ERROR test_error=$(echo -n ${array_operator[@]}|grep error) if [ -n "$(echo -n ${array_operator[@]}|grep error)" ]; then echo -n ERROR; exit 0; fi # , / # . operator=$(echo -n ${array_operator[0]} | tr -d 'operator:'|tr -d '\,') operator_id=$(echo -n ${array_operator[1]} | tr -d 'operator_id:') region=$(echo -n ${array_operator[2]} | tr -d 'region:') region_id=$(echo -n ${array_operator[3]} | tr -d 'region_id:') $sql "REPLACE INTO operators\ (id, data, to_phon_nomber, operator, operator_id, region, region_id, in_phon_nomber)\ VALUES\ (NULL,\ NULL,\ '$1',\ '$operator',\ '$operator_id',\ '$region_old',\ '$region_id',\ '$2')" #operator=$(curl -s https://phonenum.info/phone/$1|grep \:|head -n1| sed 's/\:\ //'|tr -s "[:space:]" "_"|sed -r 's/\..*//') echo -n $operator,$operator_id,$region,$region_id exit 0
Source: https://habr.com/ru/post/337150/
All Articles