I have a script which stores output of a command inside a variable like this:
However, some of the output is not being stored in the variable, I am assuming because it is delayed... I am sure its delayed because it outputs the line I want to the screen after it stored the output in the variable and I tried processing it...
[EDIT]IMPORTANT! It turns out the output was going to stderr[/EDIT]
How do I get it to wait for the exit code (when it is 100% done outputting) before storing the output into the variable?
I did not post an example because I thought the users would complain it is nefarious, however it is not, and I am running the script on my own servers. Example as requested:
# Grab the output, so we can check for error... If error then retry same password after wait time outpt="$(hydra -l $hydra_user -P $tmp_passwds $hydra_all_params $hydra_host $hydra_module)" # Grep for "ssh protocol error" line banln=$(echo "$outpt" | grep 'ssh protocol error') # Show ban status, update wait_time if [ "$banln" != "" ];then echo "[STATUS] Oops, we got banned! (increasing wait_time + 1 second)" wait_time=$wait_time+1 # Start retry procedure until not banned fi
The problem in this example is that the line I am looking for ([ERROR] ssh protocol error) seems to come after the command's output is stored in the variable