Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a shell script to run JMeter test. Script generates the Jmeter log out put and creates sar (suppose to create sar file though it does not). Shell script is -

runtest() 
{
 export JMETER_HOME=/home/software/apache-jmeter-2.6
 host=$1
 port=$2
 loopcount=$3

 logfile=jmeter$(date -d "today" +"%Y%m%d%H%M%S").jtl
 sarfile=sar$(date -d "today" +"%Y%m%d%H%M%S").dat

sar -o $sar_file 3 100000 >/dev/null 2>&1 &
sar_pid=$!;
echo 'sar started with pid' $sar_pid;

for ((start=1; start <= $loopcount; start++ ))
do
 echo 'Iteration' $start;
$JMETER_HOME/bin/jmeter.sh -n -t ReportWebService.jmx -Jhost=$host -Jport=$port -l $logfile
done
sleep 2
echo 'killing sar process id' $sar_pid
kill -9 $sar_pid;

}

runtest localhost 8087 1

When I execute the shell script, I eventually encounter error -

sar started with pid 13191
Iteration 1
Created the tree successfully using ReportWebService.jmx
Starting the test @ Tue Apr 17 11:16:24 IST 2012 (1334641584914)
Waiting for possible shutdown message on port 4445
Tidying up ...    @ Tue Apr 17 11:16:25 IST 2012 (1334641585129)
... end of run
killing sar process id 13191
./temp.sh: line 22: kill: (13191) - No such process

And I don't see any ".dat" file generated for sar data. What is wrong with this shell script? Please be gentle, I am new to world of Unix.

share|improve this question
4  
At the risk of pointing out the obvious, the sar command has evidently terminated by the time you get around to killing it. You should be investigating your sar command to see if it is working correctly. Try running the exact command outside the script. In addition, check your script for typos. In particular, your question has a typo: you set sarfile but use sar_file. Use a consistent variable naming scheme and check your original script to see if that typo exists. –  jw013 Apr 17 '12 at 6:28
    
the error was because of typo in sar_file, I wish I could mark your answer as right –  Tarun Apr 17 '12 at 6:58

1 Answer 1

up vote 1 down vote accepted

There's a typo in your question: you set sarfile but use sar_file, which is probably causing your sar command to exit with an error.

share|improve this answer
    
and I did...... –  Tarun Apr 17 '12 at 11:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.