Linux novice here so bear with me here.
I am writing a Bash Script for school (On a CentOS 8 VM) and I am attempting to save the output of Siege (Load Tester) to a variable so I can compare values.
Here is the issue I am running into: The HTTP lines between "The server is now under siege" and "Lifting the server siege..." are what are being stored in the variable, and not the nice little summary after "Lifting the server siege..."
[root@prodserver siege-4.1.1]# siege -c 1 -t 1s 192.168.1.3
** SIEGE 4.1.1
** Preparing 1 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200 0.00 secs: 6707 bytes ==> GET /
HTTP/1.1 200 0.01 secs: 2008 bytes ==> GET /assets/images/taste_bug.gif
HTTP/1.1 200 0.00 secs: 2579 bytes ==> GET /assets/images/backpack_bug.gif
HTTP/1.1 200 0.00 secs: 2279 bytes ==> GET /assets/images/desert_bug.gif
HTTP/1.1 200 0.00 secs: 1653 bytes ==> GET /assets/images/calm_bug.gif
HTTP/1.1 200 0.00 secs: 1251 bytes ==> GET /assets/javascripts/menus.js
...Shortened for readability...
HTTP/1.1 200 0.00 secs: 1251 bytes ==> GET /assets/javascripts/menus.js
HTTP/1.1 200 0.00 secs: 2579 bytes ==> GET /assets/images/backpack_bug.gif
HTTP/1.1 200 0.00 secs: 2279 bytes ==> GET /assets/images/desert_bug.gif
HTTP/1.1 200 0.00 secs: 1653 bytes ==> GET /assets/images/calm_bug.gif
HTTP/1.1 200 0.00 secs: 1251 bytes ==> GET /assets/javascripts/menus.js
HTTP/1.1 200 0.01 secs: 2008 bytes ==> GET /assets/images/taste_bug.gif
HTTP/1.1 200 0.00 secs: 2579 bytes ==> GET /assets/images/backpack_bug.gif
HTTP/1.1 200 0.00 secs: 2279 bytes ==> GET /assets/images/desert_bug.gif
HTTP/1.1 200 0.00 secs: 1653 bytes ==> GET /assets/images/calm_bug.gif
Lifting the server siege...
Transactions: 149 hits
Availability: 100.00 %
Elapsed time: 0.22 secs
Data transferred: 3.95 MB
Response time: 0.00 secs
Transaction rate: 677.27 trans/sec
Throughput: 17.97 MB/sec
Concurrency: 1.00
Successful transactions: 149
Failed transactions: 0
Longest transaction: 0.01
Shortest transaction: 0.00
Currently this is how I am attempting to store the variable in bash:
SIEGE="$(siege -c $1 -t $2 [ip])"
As mentioned before, when I echo $SIEGE, it turns out the variable stored all the HTTP lines and NOT the Summary after "Lifting the siege..."
My question is how can I store that Summary in a variable.
NOTE: I'm not familiar with
siege
so I have no idea if all of the output is going tostdout
or if some of the output could be going tostderr
.Assuming all
siege
output is going tostdout
... a couple ideas depending on which lines need to be ignored:If it turns out some of the output is being sent to
stderr
, change thesiege
call to redirectstderr
tostdout
:Though I'd probably opt for saving all output to a file and then parsing the file as needed, ymmv ...