Replaced rtpengine-ctl shell script with perl script.

pull/101/head
Frederic-Philippe Metz 11 years ago
parent fb30ef8ccd
commit cca0f2bf71

@ -1,70 +1,76 @@
#!/bin/bash #!/usr/bin/perl
#
host=127.0.0.1 use IO::Socket::INET;
port=9900
error_rc=255
prgname=${0##*/} $num_args = $#ARGV + 1;
prgdir=${0%$prgname} if ($num_args == 0) {
showusage();
exit;
}
# auto-flush on socket
$| = 1;
showusage() { my $argumentstring = "";
echo "" my $ip = "127.0.0.1";
echo " $0 [ -ip <ipaddress> -port <port> ] <command>" my $port = "9900";
echo ""
echo " Supported commands are:" for (my $argnum=0; $argnum <= $#ARGV; $argnum++) {
echo "" if ($ARGV[$argnum] eq "-ip") {
echo " list [ numsessions | sessions | session <callid> ]" die "No argument after -ip\n" unless $argnum+1<=$#ARGV;
echo " numsessions : prints the number of sessions" $argnum = $argnum+1;
echo " sessions : print one-liner session information" $ip = $ARGV[$argnum];
echo " session <callid> : print detail about one session" } elsif ($ARGV[$argnum] eq "-port") {
echo " totals : print total statistics (does not include current sessions)" die "No argument after -port\n" unless $argnum+1<=$#ARGV;
echo "" $argnum = $argnum+1;
echo " terminate [ all | <callid> ]" $port = $ARGV[$argnum];
echo " all : terminates all current sessions" } else {
echo " <callid> : session is immediately terminated" $argumentstring .= "$ARGV[$argnum] ";
echo "" }
echo ""
echo " Return Value:"
echo " 0 on success with ouput from server side, other values for failure."
echo ""
exit 0
} }
if [ $# -eq 0 ]; then showusage; fi # create a connecting socket
my $socket = new IO::Socket::INET (
PeerHost => $ip,
PeerPort => $port,
Proto => 'tcp',
);
die "Cannot connect to the rtpengine $!\n" unless $socket;
$argumentstring = trim($argumentstring);
my $size = $socket->send($argumentstring);
command -v nc 2>&1 >/dev/null # notify server that request has been sent
if [ $? -ne 0 ]; then shutdown($socket, 1);
echo "Error: $0 requires netcat to be installed."
exit 0
fi
while [ $# -gt 0 ]; do # receive a response of up to 10MB
case $1 in my $response = "";
"-?"|"-help"|"-h") $socket->recv($response, 1024*1024*10);
showusage
;; print $response;
"-ip")
shift $socket->close();
if [ $# -gt 0 ]; then
host=$1 sub showusage {
else print "\n";
echo "Missing parameter for option '-ip'" >&2 print " rtpengine-ctl [ -ip <ipaddress> -port <port> ] <command>\n";
fi print "\n";
;; print " Supported commands are:\n";
"-port") print "\n";
shift print " list [ numsessions | sessions | session <callid> | totals ]\n";
if [ $# -gt 0 ]; then print " numsessions : prints the number of sessions\n";
port=$1 print " sessions : print one-liner session information\n";
else print " session <callid> : print detail about one session\n";
echo "Missing parameter for option '-port'" >&2 print " totals : print total statistics\n";
fi print "\n";
;; print " terminate [ all | <callid> ]\n";
*) print " all : terminates all current sessions\n";
varargs="$varargs $1" print " <callid> : session is immediately terminated\n";
esac print "\n";
shift print "\n";
done print " Return Value:\n";
print " 0 on success with ouput from server side, other values for failure.\n";
print "\n";
}
echo -n ${varargs} | nc ${host} ${port} sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };

Loading…
Cancel
Save