1

Basically I am trying to write a script to stress test my server and ensure a command is running. My script is not working as intended. Below is the script. Basically the commands the script is executing are not being run asynchronously nor are their output being written to the results file. Any suggestions?

#Script to load test the swift command on a linux box

numOfTests=100
echo "Starting Swift Load Tester ($numOfTests iterations)"

mkdir /srv/www/htdocs/audiotest/stress_test
mkdir /srv/www/htdocs/audiotest/half_sec_test
mkdir /srv/www/htdocs/audiotest/sec_test

echo "This is the prompt text" > /srv/www/htdocs/audiotest/prompt.txt

echo "Beginning Stress Test..."

#Clear results text file
echo "" > results.txt

for((i=0; i < numOfTests; i++))
do
    (time /opt/swift/bin/swift -n Allison-8kHz -o /srv/www/htdocs/audiotest/stress_test/$i.wav -f /srv/www/htdocs/audiotest/prompt.txt &) >> results.txt 2>&1
done

echo "Done"
echo "Beginning 1/2 second interval test..."

for((i=0; i< numOfTests; i++))
do
    (time /opt/swift/bin/swift -n Allison-8kHz -o /srv/www/htdocs/audiotest/half_sec_test/$i.wav -f /srv/www/htdocs/audiotest/prompt.txt &) >> results.txt 2>&1
    sleep .5
done

echo "Done"
echo "Beginning 1 second interval test..."

for((i=0; i< numOfTests; i++))
do
    (time /opt/swift/bin/swift -n Allison-8kHz -o /srv/www/htdocs/audiotest/sec_test/$i.wav -f /srv/www/htdocs/audiotest/prompt.txt &) >> results.txt 2>&1
    sleep 1
done

echo "Done"

echo "Load Testing Completed"
0

2 Answers 2

2

When you use > as a redirect operator, it overwrites the file. As a result, the last test that runs will be the only output you see. Use >> instead. And time writes its output to stderr, so if you want to see those results you'll need to redirect stderr as well.

Sign up to request clarification or add additional context in comments.

5 Comments

ooooh, that could be the issue. Also, if I want to run the shell script as a process that will not be killed by my ssh connection being terminated how do I do that?
The script will only be terminated when your ssh connection drops if it attempts to write to the pipe that gets closed when ssh dies (eg, its stdout). Just redirect its output, or run it in tmux.
Edited the code but still not getting exactly what I want, but is that closer?
@thatidiotguy: If you edit your question with revisions based on answers or comments (e.g. that are not corrections of a typo) that remove the issue that is the basis for the question, then the answers don't make sense and subsequent answerers have a difficult time following along. Please make this type of edit as an addition rather than a revision. Otherwise, the revisions look like they are part of the issue at hand.
Understood. Sorry about the confusion.
1

use a subshell and redirect stderr as well, to see if it work for you.

(time myCommand [args] &) > results.txt 2>&1

6 Comments

hmmm, so when I try that I get nothing to ouput and my ssh connection gets terminated. When I log back in and check the results file I just a message telling me that my shell script was terminated.
ah sorry, you want to accumulate the results in the loop. sorry, i missed that part and only focussed on getting stderr output recorded. it seems the other solution pointed out that already. also, are you sure you are using bash explicitly? my usage was only for bash. you have bash tag so i assumed it was bash.
Well I am running it like nohup sh myScript.sh & Is that correcT?
if you are backgrounding the entire script, then you don't need the background in the time command, i.e., try (time myCommand [args]) >> results.txt 2>&1
But i do not want the script to wait for the return of the swift command. I want it to immediately continue and call it again, hence stress testing the server. Does that make sense?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.