0% found this document useful (0 votes)
63 views

Linphone Call

This Bash script automates making a phone call and playing a recorded audio message. It sets SIP server and authentication details, checks for required programs, records a message, registers the client, makes an outbound call, plays the recorded audio, monitors the call state, and cleans up after completing or terminating the call.

Uploaded by

vitry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Linphone Call

This Bash script automates making a phone call and playing a recorded audio message. It sets SIP server and authentication details, checks for required programs, records a message, registers the client, makes an outbound call, plays the recorded audio, monitors the call state, and cleans up after completing or terminating the call.

Uploaded by

vitry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#!

/bin/bash
########################################
SIP_HOST='192.168.123.151'
SIP_USER='test'
SIP_PASS='test'
CALL='10'
TEXT2WAVE='/usr/bin/text2wave'
TMPDIR='/usr/local/icinga/etc/objects'

########################################
get_phone_state () {
linphonecsh status register 2>/dev/null 1>&2
if [ $? -eq $1 ]; then
true
else
false
fi
}
get_call_state () {
linphonecsh status hook 2>/dev/null 1>&2
if [ $? -eq $1 ]; then
true
else
false
fi
}
function usage(){
echo "usage: $0 -r -m \"<message>\""
exit 1
}
if [ $# -lt 2 ]; then
usage
fi
while getopts "r:m:" OPTION; do
case $OPTION in
r)
RECIPIENT="sip:$OPTARG@$SIPREALM"
;;
m)
MESSAGE="$OPTARG"
;;
*)
usage
;;
esac
done
#Check
if [ ! -x "$TEXT2WAVE" ]; then
echo "$TEXT2WAVE not found!"
exit 1
fi
if [ "$RECIPIENT" = "" ]; then
usage
fi
if [ "$MESSAGE" = "" ]; then
usage
fi
# Create Date
DATE=`date +%y%m%d%k%M|sed 's/ /0/'`
# generate message
MSGWAV=$TMPDIR/$DATE.$RANDOM.wav
$TEXT2WAVE -o $MSGWAV -f 8000 << EOF
$MESSAGE
EOF
# ret code 255 = no daemon started
if get_phone_state 255; then
echo "Starting Phone client ..."
linphonecsh init
while get_phone_state 255; do sleep 0.2; done
else echo "Phone client already started ..."
fi

# ret code 0 = unregistered


# ret code 1 = registered
if get_phone_state 0; then
echo "Register Client on SIP Server ..."
linphonecsh register --host ${SIP_HOST} --username ${SIP_USER} --password ${SIP
_PASS}
else echo "Client already registered ..."
fi
while ! get_phone_state 1; do sleep 0.2; done
echo "using soundcard as file"
linphonecsh soundcard use files
echo "Calling Number: ${CALL} ..."
linphonecsh dial ${CALL}
while get_call_state 4; do sleep 10; done
echo "Ringing on remote site ..." # what the heck,.. no hook=ringing or stuff li
ke that
echo "play wav file"
linphonecsh generic "play ${MSGWAV}"

echo -n "Press any key to terminate the call ... "


ABORT=false
while [ "`linphonecsh status hook`" == "" ] && ! ${ABORT}; do
read -n1 -s -t 1; ABORT=$?
if [ ${ABORT} -eq 0 ]; then ABORT=true; else ABORT=false; fi
done
if get_call_state 32; then echo -n "call established"; fi
while get_call_state 32 && ! ${ABORT}; do
read -n1 -s -t 1; ABORT=$?
if [ ${ABORT} -eq 0 ]; then ABORT=true; else ABORT=false; fi
done
echo
echo "Cleaning up ..."
linphonecsh generic terminate 2>&1 1>/dev/null
echo "Exiting Daemon ..."
linphonecsh exit
echo

You might also like