-
Notifications
You must be signed in to change notification settings - Fork 19
/
asterisk_reg.sh
49 lines (29 loc) · 1.15 KB
/
asterisk_reg.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
pidof -o %PPID -x $0 >/dev/null && echo "ERROR: Script $0 already running" && exit 1
DB_USER="root"
DB_PASSWD=""
DB_NAME="pushdb"
DB_TABLE="pushdb_pushkeys"
#One of the users suggested using commented lines for better performance
#tail -Fn0 /var/log/asterisk/full | grep --line-buffered "Registered SIP" | \
#while read line ;
tail -Fn0 /var/log/asterisk/full | \
while read line ;
do
echo "$line" | grep "Registered SIP" > /dev/null
if [ $? = 0 ]
then
US=$(echo "${line}" | sed -e "s/.*Registered SIP '\(.*\)' at.*/\1/")
TK=$(asterisk -r -x "sip show peer $US" | sed -n "s/.*pn-prid=\(.*\):remote&.*/\1/p")
ACPTLEN=64
TKLENGTH=$(echo -n $TK | wc -m)
if [ "$TKLENGTH" = "$ACPTLEN" ]; then
DT=$(TZ=EEST date +'%F %T')
mysql --user=$DB_USER --password=$DB_PASSWD $DB_NAME << EOF
INSERT INTO $DB_TABLE (\`p_device\`, \`p_status\`, \`p_type\`, \`p_info\`, \`p_updated\`) VALUES ("$US", "1", "IOS", "$TK","$DT") ON DUPLICATE KEY UPDATE \`p_device\`=VALUES(\`p_device\`),\`p_status\`=VALUES(\`p_status\`),\`p_type\`=VALUES(\`p_type\`),\`p_info\`=VALUES(\`p_info\`),\`p_updated\`=VALUES(\`p_updated\`);
EOF
else
:
fi
fi
done