Bash scripting problem!
Heya,
I'm currently working on a bash script that'll simplify my laptop connecting to wireless APs, instead of running iwconfig and wpa_supplicant I'd just run something like Code:
wirec myAP eth2 How do I get the output of a command in an if statement, check it and split the results? I want the if statement to run /usr/sbin/iwconfig $IFACE and grep for */100 then split that to get the * result (so the script can check for > 10% connectivity). If someone could suggest how to do this in a bash script if statement, and also how to check that dhcpcd has obtained an IP for that adapter, I'd be more grateful! |
return status of the previous command executed
use $? if 0 - operation success else failure is that what you are looking for ? |
This is an example of how you can achieve that with awk+grep. I'm not an awk expert so I hope someone will post a more beautiful code.
NOTE: this is untested code; I don't have any wireless network around right now. Code:
#!/bin/bash Quote:
Code:
ifconfig eth0 | grep -q "inet addr:" && echo "I have an IP" |
All times are GMT -5. The time now is 05:20 AM. |