OK, so I'm going on vacation for 2 weeks and the Mrs will kill me if I work at all. So here's the quick and dirty with suggested improvements at the end.
Pretend 1111 has a team or brdg of 2222
2 db queries
First: return 1111,2222,10 - that would mean 1111 has either a brdg or a team for 2222 on button 11 of their module
*I'm only looking at button modules and they start counting at 0. The first button on module 2 = button 24
*also, I'm lazy and in a hurry. It only works on a 4 digit dial plan.
Second: return extensions, names
So you'd run this in your SMGR as root:
Code:
mgmtia -t -A -f ./all.sql > allTeamAndBrdgOnModules.txt
mgmtia -t -A -f ./names.sql > names.txt
The contents of allTeamAndBrdgOnModules.sql
Code:
SELECT
ipt_extension.extension,
ipt_expmodule_button.data2,
ipt_expmodule_button.number
FROM
ipt_extension
INNER JOIN ipt_station
ON ipt_extension.id = ipt_station.extension_id
INNER JOIN ipt_expmodule_button
ON ipt_station.id = ipt_expmodule_button.station_id
WHERE ipt_expmodule_button.type = 'team' or ipt_expmodule_button.type = 'brdg-appr';
and names.sql
Code:
SELECT
ipt_station.name,
ipt_extension.extension
FROM
ipt_extension
INNER JOIN ipt_station
ON ipt_extension.id = ipt_station.extension_id
then run script.sh
Code:
#!/bin/bash
input="/home/smgradmin/scripts/allTeamAndBrdgOnModules.txt"
while read line; do
user=`echo $line | sed 's/|.*//g'`
buttonnumber=`echo $line | sed 's/.*|//'`
realbutnum=`expr $buttonnumber + 1`
otheruser=`echo $line | cut -c6- | sed 's/|.*//g'`
lastname=`cat names.txt|grep $otheruser|sed 's/|.*//g' |sed 's/,.*//'`
initial=`cat names.txt|grep $otheruser|sed 's/|.*//g'|sed 's/.*, //' |cut -c1-1`
if [[ "$realbutnum" < 10 ]]
then
echo SBMLABEL0$realbutnum=$initial $lastname
else
echo SBMLABEL$realbutnum=$initial $lastname
fi
#echo $realbutnum
done < "$input"
That will print
Code:
root >sh script.sh
SBMLABEL01=D Paul
SBMLABEL01=D Paul
SBMLABEL01=C 034
SBMLABEL2=C 034
SBMLABEL25=D Hyde
SBMLABEL26=D Hyde
Something's wrong with my bash script cause I'd expect SMBLABEL2=C 034 to be SMBLABEL02, but it works for SMBLABEL01
So what you really want is:
-Something that runs all the time
-Something that updates the label if it changes - like if 1111 has button 1 and 2 for 2222 and 3333 and for some reason you flipped that to be 3333 and 2222, the script should update it.
So I'd do something like grep SMBLABEL01 from $user_96xxdata.txt
If it the button label doesn't exist, echo the line to the end of $user_96xxdata.txt
If the button label is as it should be, leave it alone.
If the button label was there and changed, use sed to swap the new one we pulled from the SMGR db to overwrite the one in $user_96xxdata.txt
See ya in a couple of weeks.
