Reputation: 461
I have a below code written to get the Speed of the current running interface on the Linux but when i'm running this script its just throwing the error : TypeError: execv() arg 2 must contain only strings
.
would appreciate any help or ideas.
Below is the script:
In the Below script i have 2 functions created
1) The one is get_Inf()
which gives the Interface information.
2) The Second One is get_intSpeed()
which takes the interface name from the First functon and pass it the os command ethtool
which further parsed in via a regex to Fetch only the Speed like 1000Mb/s
.
#!/grid/common/pkgs/python/v2.7.10/bin/python
import subprocess
import netifaces
import re
''' This snippet is just to get the Speed of the running interface on the System '''
def get_Inf():
Current_inf = netifaces.gateways()['default'][netifaces.AF_INET][1]
return get_Inf
def get_intSpeed():
spd = subprocess.Popen(['/sbin/ethtool', get_Inf()], stdout=subprocess.PIPE).communicate()[0]
pat_match=re.search(".*Speed:\s+(\d+Mb/s)\s+.*", spd) # "d" means any number of digit following the "Mb/s".
speed = pat_match.group(1)
return speed
def main():
print get_intSpeed()
main()
Below is the os command
/sbin/ethtool
which has the Speed information of the Interface along with Other Information.
[root@tss /]# /sbin/ethtool eth0| grep Speed
Speed: 1000Mb/s
[root@tss /]# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown
Supports Wake-on: g
Wake-on: g
Link detected: yes
I am using python version 2.7.10.
Upvotes: 1
Views: 1367
Reputation: 375
Your get_Inf()
function will return itself with the return get_Inf
statement, which is not a string, that is why execv
(which is called by subprocess.Popen
) is complaining. You should return Current_Inf
from your function.
Upvotes: 2