Bash: add value to array if command fails
I'm trying to loop through a list of hosts from a DNS server to get their ifspeed using ssh and running the ethtool command. The problem is that some of the servers do not have ethtool installed.
For the servers that do have ethtool installed, the value is added to the array. What I'd like to do is add an arbitrary value to the array even if ethtool fails on the sever such that a spreadsheet can be produced with the proper count of hosts, and results returned for ethtool.
I originally started with the following which gives me the speed for any host that has ethtool installed.
ifspeed_array+=($(/usr/bin/ssh $USER@$HOST sudo ethtool eth0 | grep -i "speed" | awk '{print $2}'))
I thought doing an 'or' in the grep would add a value for servers without ethtool installed but no luck there.
ifspeed_array+=($(/usr/bin/ssh $USER@$HOST sudo ethtool eth0 | grep -i "speed\|found" | awk '{print $2}'))
Any thoughts, other than installing ethtool on the servers that don't have it installed already?
Thanks!
|