puppet/modules/rhizo_base/templates/rccn-functions.sh.erb

165 lines
4.7 KiB
Text

#
# Shell Functions for Rhizomatica Community Celular Network
#
OSMO_STACK="<%= @osmo_stack %>"
OSMO_HLR_OLD="/var/lib/osmocom/hlr.sqlite3"
OSMO_HLR="<%= @hlr_db %>"
OSMO_SMS="<%= @sms_db %>"
DID="<%= @voip_did %>"
waitfor0calls () {
while (( $((`fs_cli -x "show calls count" | awk '$1{print $1}'`)) > 0 ))
do
sleep 1
done
}
chans ()
{
while [ 1 == 1 ]; do
_output=`fs_cli -x 'show channels as delim |' | csvcut -d\| -c 3,2,6,8,10,11,13,15,18 | csvlook -I`;
clear;
echo "$_output";
sleep 1;
done
}
topcalls () {
while [ 1 == 1 ]
do
clear
fs_cli -x "show calls" \
| gawk -F, '!/uuid/ && !/^$/ && !/total/ { printf "\033[34;1m" $8 "("$28") \033[0m \033[200D\033[25C calls \033[32;1m "$10"("$30") \033[0m \033[200D\033[60C for %02d:%02d:%02d \033[200D\033[80C \033[31;1m Call State: "$6"/"$13"/"$33 "\n",(systime()-$4)/60/60%24,(systime()-$4)/60%60,(systime()-$4)%60 }' \
| sed "s/$DID/DID/g" \
| sort -r -k5
echo "show lchan " | nc -q1 localhost 4242 | awk 'BEGIN { RS = "BTS"; FS = "\n" } /TCH/ {print $7"\t\t\t\t BTS"$1} '
sleep $1
done
}
nitb() {
/usr/bin/expect -c 'spawn telnet localhost 4242;send "enable\r";send "logging enable\r";send "logging level all everything\r";send "logging print category 1\r";send "logging level smpp fatal\r"; send "logging filter all 1\r"; interact'
}
hlr() {
sudo /usr/bin/sqlite3 -column -header $OSMO_HLR
}
hlr2() {
sudo /usr/bin/sqlite3 -column -header $OSMO_HLR_OLD
}
sms() {
sudo /usr/bin/sqlite3 -column -header $OSMO_SMS
}
tl() {
if [ "$1" == "" ] ; then
tail -f /var/log/rccn/*log
else
less -RS +F /var/log/rccn/$1.log
fi
}
r() {
sudo -i bash -c "cd /var/rhizomatica/rccn; exec bash --login"
}
o() {
sudo -i bash -c "cd /etc/osmocom; exec bash --login"
}
f() {
tmux new-session -n SIP "sudo sngrep -d any" \; splitw -p 60 "fs_cli -r" \; select-window -t SIP \;
}
rk_ext() {
IMSI=$(curl -X GET http://10.23.0.3:8098/buckets/hlr/index/msisdn_bin/$1 2>/dev/null| python -c "import sys, json; print json.load(sys.stdin)['keys'][0]")
echo $IMSI
rk_imsi $IMSI
}
rk_imsi() {
JSON=$(curl -X GET http://10.23.0.3:8098/buckets/hlr/keys/$1 2>/dev/null)
echo $JSON
echo -n "That's a Last Update of: "
echo $JSON | cut -d\ -f6 | gawk '{print strftime("%c", $0, 1)}'
echo
}
check_trx() {
echo "show trx" | nc -q1 localhost 4242 | awk 'BEGIN { RS="TRX"; } /OK/ { print "BTS"$4" TRX"$1": OK"; }'
}
<% @bts.each_with_index do |bts, index| -%>
b<%= index %>() {
ssh -t -o StrictHostKeyChecking=no <%= @bts_user[bts["model"]] %>@<%= bts["ip"] %> $*
}
<% end -%>
bA() {
tmux start-server
tmux new -s bts -d -n BTS0 "source /etc/profile.d/rccn-functions.sh ; b0"
# This won't look great for more than 4 windows, but
# that is not a lot of space anyway.
pane=0
for bts in "${!BTS[@]}" ; do
if [ $bts == 0 ] ; then continue; fi
if [ $bts == 3 ] ; then
pane=2;
fi
if [ $bts -lt 2 ] ; then
split=h
else
split=v
fi
tmux split-window -t $pane -$split "source /etc/profile.d/rccn-functions.sh ; b$bts"
done
tmux attach -t bts
}
pdp () {
expect -c 'spawn -noecho telnet 0 4245; expect >; send enable\r; expect #; send "show pdp-context all\r"; expect #' | grep "PDP Address" | grep -v invalid | sort -t. -n -k3,3n -k4,4n;
echo Count: $(pdpc)
}
pdpc () {
expect -c 'spawn -noecho telnet 0 4245; expect >; send enable\r; expect #; send "show pdp-context all\r"; expect #' | grep "PDP Address" | grep -v invalid | wc -l
}
mmc () {
expect -c 'spawn -noecho telnet 0 4245; expect >; send enable\r; expect #; send "show mm-context all\r"; expect #' | grep IMEI | wc -l
}
ns () {
expect -c 'spawn -noecho telnet 0 4245; expect >; send enable\r; expect #; send "show ns\r"; expect #' | grep ALIVE;
}
pp () {
ps awxf | grep [p]ython
}
op () {
ps awxf | grep [o]smo\-
}
lock () {
if [ "$1" == "" ] ; then
echo "BTS #?"
return
fi
expect -c 'set bts '$1'; spawn telnet localhost 4242; expect ">"; send "enable\r"; expect "#"; send "configure terminal\r"; expect "#";
send "network\r"; expect "#"; send "bts $bts\r"; expect "#"; send "trx 0\r"; expect "#"; send "rf_locked 1\r";
expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"';
}
unlock () {
if [ "$1" == "" ] ; then
echo "BTS #?"
return
fi
expect -c 'set bts '$1'; spawn telnet localhost 4242; expect ">"; send "enable\r"; expect "#"; send "configure terminal\r"; expect "#";
send "network\r"; expect "#"; send "bts $bts\r"; expect "#"; send "trx 0\r"; expect "#"; send "rf_locked 0\r";
expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"';
}