#!/bin/bash#run expect script to connect to asterisk AMI and login, turn off event output, and grab the tech support queue length/etc/monitor/parse.exp > /dev/null 2>&1#put the queue length in a variablelen=`grep "^2 *has" x_test | cut -d " " -f 14`echo $lenif [ $len -ge 2 ] ; thenecho "FAIL" > /var/www/queuelength.htmlelseecho "OK" > /var/www/queuelength.htmlfi[root@asterisk1 monitor]#[root@asterisk1 monitor]# cat parse.exp#!/usr/bin/expect## Usage: ./vmcount.exp 1234@default# The user account from manager.conf:set username ""set secret ""set host "127.0.0.1"set port "5038"# Open connection to AMI:spawn telnet $host $port# Just in case telnet aborts because it cannot connect:expect_before eof { send_user "Failed to connect.\n" exit 1}# Wait for the text "Manager"; once received, send a login packet:#expect "Manager/1.0" { send_user "Connected.\n" send "Action: Login\nEvents: off\nUsername: $username\nSecret: $secret\n\n" # Please note that telnet automatically converts line feeds # (\n) to CR LF (\r\n) - so you must not write \r\n here.}# Login successful?:#log_file -noappend /etc/monitor/x_testexpect "Success"send "Action: Queues\n\n"expect "default"send "Action: Logoff\n\n"log_file