iwconfig grep output as part of a script

1.3k Views Asked by At
#!/bin/bash
MAX=20
while true
do
iwconfig wlan0 txpower $(((RANDOM % $MAX) +1))
set -x #this was not originally included
echo iwconfig wlan0 | grep Tx-Power
done

So I am trying to have a small script vary the tx power of my device below the max. I had this working no problem a while back and have revisted the script now. Since then I have changed host and VM that this is running on and without the set-x it just hangs. Each line works individuall, but it will not output the echo to the screen when in a script.

When I add the set -x it works but also echos set -x, done etc to the screen also.

Any idea what has caused this change and how I could fix

A

1

There are 1 best solutions below

2
On BEST ANSWER

Your script runs in a endless loop It also contains the following line:

 echo iwconfig wlan0 | grep Tx-Power

so you simply echo string "iwconfig wlan0" and then you try to find "Tx-Power" in this script.

change this line to:

iwconfig wlan0 | grep Tx-Power

so at least you will be able to see Tx-Power in the output.