-1
我有一個很奇怪的請求。我正在嘗試腳本來幫助配置vlans工作。我想要它做的是讀第1行完整的腳本的其餘部分。然後返回閱讀第2行...完成腳本的其餘部分等等,直到完成。
這是我目前的配置
file=open("C:\\Users\\KM003308023\\final.txt","w")
file.write("")
file=open("C:\\Users\\KM003308023\\final.txt","a")
interface= open ("C:\\Users\\KM003308023\\int.txt")
pull= open ("C:\\Users\\KM003308023\\int.txt")
y= str(input("enter Port description:"))
p= str(input("Enter DATA vlan:"))
x= str(input("Enter voice vlan:"))
portconfig= "\n switchport port-security \n switchport port-security maximum 3 \n switchport port-security aging time 30 \n switchport port-security violation restrict \n switchport port-security aging type inactivity \n no logging event link-status \n no cdp enable \n spanning-tree portfast \n spanning-tree bpduguard enable \n no shut\n!\n"
output=""
for j in pull.readlines():
output=(output + "default int " + j + "!\n")
for f in interface.readlines():
output =(output + "int " + f +"description " + y + "\n switchport \n switchport access vlan " + p + "\n switchport mode access \n switchport voice vlan " + x + portconfig)
file.write(output)
file.close()
我想它做的是從int.txt
- 拉readline1
- line 1
- whe再次readlines1並輸出所有需要的垃圾。電流輸出的
例如:
default int fa 2/0/15
!
default int fa 7/0/1
!
default int fa 7/0/8
!
int fa 2/0/15
description UHC_VLAN2
switchport
switchport access vlan 52
switchport mode access
switchport voice vlan 53
switchport port-security
switchport port-security maximum 3
switchport port-security aging time 30
switchport port-security violation restrict
switchport port-security aging type inactivity
no logging event link-status
no cdp enable
spanning-tree portfast
spanning-tree bpduguard enable
no shut
!
int fa 7/0/1
description UHC_VLAN2
switchport
switchport access vlan 52
switchport mode access
switchport voice vlan 53
switchport port-security
switchport port-security maximum 3
switchport port-security aging time 30
switchport port-security violation restrict
switchport port-security aging type inactivity
no logging event link-status
no cdp enable
spanning-tree portfast
spanning-tree bpduguard enable
no shut
!
int fa 7/0/8
description UHC_VLAN2
switchport
switchport access vlan 52
switchport mode access
switchport voice vlan 53
switchport port-security
switchport port-security maximum 3
switchport port-security aging time 30
switchport port-security violation restrict
switchport port-security aging type inactivity
no logging event link-status
no cdp enable
spanning-tree portfast
spanning-tree bpduguard enable
no shut
!
What i would like to see:
default int fa 2/0/15
!
int fa 2/0/15
description UHC_VLAN2
switchport
switchport access vlan 52
switchport mode access
switchport voice vlan 53
switchport port-security
switchport port-security maximum 3
switchport port-security aging time 30
switchport port-security violation restrict
switchport port-security aging type inactivity
no logging event link-status
no cdp enable
spanning-tree portfast
spanning-tree bpduguard enable
no shut
!
default int fa 7/0/1
!
int fa 7/0/1
description UHC_VLAN2
switchport
switchport access vlan 52
switchport mode access
switchport voice vlan 53
switchport port-security
switchport port-security maximum 3
switchport port-security aging time 30
switchport port-security violation restrict
switchport port-security aging type inactivity
no logging event link-status
no cdp enable
spanning-tree portfast
spanning-tree bpduguard enable
no shut
!
,以此類推,直到它耗盡線。
我是新來的,所以試圖仍然得到我的Barrings。
這個問題可能寫得不好,但不添加註釋downvoting它,解釋什麼是缺失以及如何編輯問題只是粗魯。 – ands
你可以解釋一下這些步驟(1.從int.txt中拉出readline1,2.輸出默認的int xxx,3. ...,4. ....,5. ....)稍微好一點。我不明白你想要什麼。 – ands