using bash and curl to send file from server to client
so i am trying to solve this lab on deterlab.net. but i cant figure out exactly how to create my bash file with the curl instruction in order to created a web traffic stream between the client and the server nodes by writing a script at the client that each second gets index.html from the server. The full purpose of this lab is to create a DOS attack and flood the created traffic after. The attacking part i can manage but the bash file with the curl i cannot.this is what i have so far:
#!/bin/bash
# traffic between client and server
x=1
a = 1000000
while [ x < a]
do curl -o index.html x =x + 1
doneCan someone please help me ?
1 Answer
Leverage a C-style for looping construct:
#!/bin/bash
for ((x=1; x<1000000; x++)); do curl -o index.html
doneIn ((x=1; x<1000000; x++)):
x=1initializesxto 1x<1000000is the condition, the loop will run as long asxis less than 1000000x++incrementsxwith adding 1 after each run of loop
You have some syntactic mistakes:
To refer to the value of a variable, you need
$variablei.e. put the$in front, also it is almost always desired to have quoting around that to prevent word splitting and glob expansion:"$variable"There can't be any whitespace around
=while declaring variables,s oa = 1000000is wrong. You needa=1000000[ x < a]: here[does not support arithmetic operators like<, you need to use-lt(less than), otherwise it is just doing string comparison. You need:[ "$x" -lt "$a" ]. Also consider using the[[builtin ofbashinstead of[. For arithmetic operation you can use((too, this will allow you to use all the arithmetic operatorsx =x + 1is a syntax error, you can not have whitespace around=while declaring variables as mentioned earlier, also+ 1afterxis meaning nothing and shell will treat it as separate word (command) with variablex=xin it's environment. you need(( x=x+1 ))or((x+=1))or simply(( x++ )).
So your script can take the final form:
#!/bin/bash
# traffic between client and server
x=1
a=1000000
while (( x < a )); do curl -o index.html (( x++ ))
done 7