As this seems to be the problem:
"takes far too long to timeout and exit" I can think of a couple of solutions.
In bash, you put the phone cmd into the background
# Phone_and_terminate script
#!/bin/bash
phone_script &
#$! is last background cmd pid
sleep 30
kill -9 $!
In Perl, you'd use wrap a SIGALRM around it
To interrupt a long-running operation, set a SIGALRM handler to call die. Set an alarm with alarm, then eval your code:
Code:
$SIG{ALRM} = sub { die "timeout" };
eval {
alarm(3600);
# long-time operations here
alarm(0);
};
if ($@) {
if ($@ =~ /timeout/) {
# timed out; do what you will here
} else {
alarm(0); # clear the still-pending alarm
die; # propagate unexpected exception
}
}