के लिए बैश/अपेक्षा स्क्रिप्ट मैं आम तौर पर उम्मीद और स्क्रिप्टिंग के लिए नया हूं। मैं नेटवर्क डिवाइस कॉन्फ़िगरेशन खींचते समय अपनी जिंदगी को थोड़ा आसान बनाने के लिए कुछ स्क्रिप्ट बनाने की कोशिश कर रहा हूं। मैं एक डिवाइस के लिए एसएसएच को मूल उम्मीद स्क्रिप्ट बनाने और कॉन्फ़िगरेशन को सहेजने में कामयाब रहा।एसएसएच
मैं इस पर विस्तार करना चाहता हूं और स्क्रिप्ट को सिर्फ एक जैसा है जैसे कि सिर्फ एक आईपी पते से कनेक्ट करने की अनुमति देता हूं। मेरे पास list.txt
नामक एक फ़ाइल है जो प्रत्येक आईपी के साथ एक अलग लाइन पर कुछ अलग आईपी पते के साथ है।
अपेक्षित स्क्रिप्ट इन आईपी पते में से प्रत्येक से कनेक्ट होने और स्क्रिप्ट में शेष कार्यों को करने के लिए मुझे क्या करने की आवश्यकता होगी?
यहाँ स्क्रिप्ट मैं अब तक है उम्मीद है:
#!/usr/bin/expect -f
#Tells interpreter where the expect program is located. This may need adjusting according to
#your specific environment. Type ' which expect ' (without quotes) at a command prompt
#to find where it is located on your system and adjust the following line accordingly.
#
#
#Use the built in telnet program to connect to an IP and port number
spawn ssh 192.168.1.4 -l admin
#
#The first thing we should see is a User Name prompt
#expect "login as:"
#
#Send a valid username to the device
#send "admin"
#
#The next thing we should see is a Password prompt
expect "Password:"
#
#Send a vaild password to the device
send "password\n"
#
#If the device automatically assigns us to a priviledged level after successful logon,
#then we should be at an enable prompt
expect "Last login:"
#
#Tell the device to turn off paging
#
#After each command issued at the enable prompt, we expect the enable prompt again to tell us the
#command has executed and is ready for another command
expect "[email protected]"
#
#Turn off the paging
send "set cli pager off\n"
#
#Show us the running configuration on the screen
send "show config running\n"
#
# Set the date.
set date [timestamp -format %C%y%m%d]
#
#Test output sent to file with a timestamp on end
#-noappend will create a new file if one already exists
log_file -noappend /home/test.cfg$date
#
expect "[email protected]"
#
#Exit out of the network device
send "exit\n"
#
#The interact command is part of the expect script, which tells the script to hand off control to the user.
#This will allow you to continue to stay in the device for issuing future commands, instead of just closing
#the session after finishing running all the commands.`enter code here`
interact
मैं एक बैश स्क्रिप्ट के साथ इस एकीकृत करने के लिए की जरूरत है? यदि हां, तो क्या list.txt
फ़ाइल की एक पंक्ति को पढ़ना संभव है, इसे आईपी/होस्ट चर के रूप में उपयोग करें और फिर अगला पढ़ें और दोहराएं?
क्या आप अपने डिवाइस को एसएसएच कुंजी का उपयोग करने के लिए कॉन्फ़िगर कर सकते हैं? यदि हां, तो आपको बिल्कुल उम्मीद की आवश्यकता नहीं है। –