Hi all,
I'm trying to run the sipp simulator in crontab but after some attempt I came to the conclusion that for some reason this isn't possible (maybe due to sipp interactive nature).
This is confirmed by these posts.
Now I'm trying to launch sipp from an expect script that runs in crontab.
What I need is to grab the exit code of sipp to decide if the system is working (exit code == 0) or not (exit code != 0).
I searched all the afternoon trying to make this working but with no luck.
Here is the code I wrote:
#!/usr/bin/expect
set SERVER [lindex $argv 0]
set MYSCENARIO [lindex $argv 1]
set MRFP [lindex $argv 2]
set SERVICE [lindex $argv 3]
set LOCAL_IP [lindex $argv 4]
set IP_RTP [lindex $argv 5]
set media_port [lindex $argv 6]
set MAXCALLS [lindex $argv 7]
set RATE [lindex $argv 8]
set RATEPERIOD [lindex $argv 9]
set TIMEOUT [lindex $argv 10]
set TRACEMSG [lindex $argv 11]
set timeout 60
spawn ssh $SERVER
expect "password:" {
send "ChangeMe\r"
expect "*]#*" {
send "sipp -sf /scripts/MRF_Probe/$MYSCENARIO.xml $MRFP -s $SERVICE -i $LOCAL_IP -mi $IP_RTP -mp $media_port -rtp_echo -m $MAXCALLS -r $RATE -rp $RATEPERIOD -timeout $TIMEOUT -trace_err -trace_screen $TRACEMSG\r"
expect "*]# "
send "echo \$?\r"
expect "*]# "
set exit_status $expect_out(buffer)
send_user "EXIT CODE: $exit_status"
}
}
exit $exit_status
This seems to work fine but unfortunately the variable $exit_status gets this value (two rows):
I guess I use the wrong way: I should use the wait() function in expect, something like:
spawn true
catch wait reason
lindex $reason 3
But I can't figure out how to do this.
I didn't found much examples on the net...
Can anyone help, please?
Thanks in advance,
Evan
---------- Post updated 23-09-10 at 10:48 AM ---------- Previous update was 22-09-10 at 06:40 PM ----------
This morning I found out how to get the exit code from the expect script, here is the code:
#!/usr/bin/expect
set SERVER [lindex $argv 0]
set MYSCENARIO [lindex $argv 1]
set MRFP [lindex $argv 2]
set SERVICE [lindex $argv 3]
set LOCAL_IP [lindex $argv 4]
set IP_RTP [lindex $argv 5]
set media_port [lindex $argv 6]
set MAXCALLS [lindex $argv 7]
set RATE [lindex $argv 8]
set RATEPERIOD [lindex $argv 9]
set TIMEOUT [lindex $argv 10]
set TRACEMSG [lindex $argv 11]
set timeout 60
spawn ssh $SERVER
expect "password:" {
send "ChangeMe\r"
expect "*]#*" {
spawn /SIPP/sipp -sf /scripts/MRF_Probe/$MYSCENARIO.xml $MRFP -s $SERVICE -i $LOCAL_IP -mi $IP_RTP -mp $media_port -rtp_echo -m $MAXCALLS -r $RATE -rp $RATEPERIOD -timeout $TIMEOUT -trace_err -trace_screen $TRACEMSG
expect "*]# "
catch wait reason
set exit_status [lindex $reason 3]
send_user "EXIT CODE: $exit_status\r"
}
}
exit $exit_status
Now I have another problem: it doesn't work from crontab, I get 127 exit code from the bash script in crotnab that recall the expect ... any ideas?
---------- Post updated at 11:46 AM ---------- Previous update was at 10:48 AM ----------
Got also this last one with export TERM:
#!/bin/bash
export TERM=xterm
MYSCENARIO=$1
SUTSIP=$2
#SUTSIP=10.188.1.231
SERVICE=ivr
RATE=200
RATEPERIOD=1000
MAXCALLS=1
TIMEOUT=30
MRFP=$SUTSIP:5061
LOCAL_IP=10.130.9.39
IP_RTP=10.130.9.52
media_port=5061
RETVAL=0
\rm *.log
if [ $MAXCALLS = "1" ]
then
TRACEMSG="-trace_msg"
fi
#Eseguo il comando da script expect
/scripts/MRF_Probe/runtest.exp $SUTSIP $MYSCENARIO $MRFP $SERVICE $LOCAL_IP $IP_RTP $media_port $MAXCALLS $RATE $RATEPERIOD $TIMEOUT $TRACEMSG > /dev/null
RETVAL=$?
if [ $RETVAL == "0" ]
then
echo RETVAL=$RETVAL";"DATE=`date +%Y%m%d%H%M%S`
else
echo RETVAL=$RETVAL";"DATE=`date +%Y%m%d%H%M%S`";"See errors in *error.log
fi
exit $RETVAL