#!/usr/bin/perl # (c) Pali 2019, Perl license use strict; use warnings; use Net::Telnet; use Time::HiRes qw(usleep); die "Usage: $0 host pass ast_user\n" unless @ARGV == 3; my $host = $ARGV[0]; my $pass = $ARGV[1]; my $user = $ARGV[2]; my $t = Net::Telnet->new(Timeout => 3, Prompt => '/[^\n]*> $/'); $t->open($host); $t->waitfor('/Password :$/'); $t->print($pass); $t->waitfor($t->prompt); foreach ('open', ('key volup') x 16, 'close') { if (system('sh', '-c', qq[asterisk -rx "core show channels" |grep -q "$user"]) != 0) { print STDERR "Call ended, exiting"; last; } $t->cmd("test $_"); usleep 200_000; } $t->print("exit"); $t->close();