05-27-2020 01:58 AM
Hi,
I want to create script to just a copy running-config to tftp server. Or anyone knows command to execute the same task without prompting for input.
I am running following command on cisco ASA box.
#copy running-config tftp:<IP address>/<director name>, after executing the command it asks following questions.
Source file name ?
IP address ?
Destination file name ?
I need command or script where system should not ask me any questions, once i give all parameters in the command.
Regards
Pradip
05-27-2020 03:03 AM - edited 05-27-2020 08:39 AM
Hi
Can you use Python script?
Edit:
Removed script - working script in the next post.
05-27-2020 06:51 AM
I will give a try, i need to get into python which i never worked. But thank you for sharing the code !
Anyone has any suggestion to solve this in one single command or simple shell script, will be useful.
Regards
Pradip
05-27-2020 08:49 AM
Try this -
#!/usr/bin/expect -f set ASAIP [lindex $argv 0] set USER [lindex $argv 1] set PWD [lindex $argv 2] set TFTP [lindex $argv 3] set DSTFILE [lindex $argv 4] spawn ssh $USER@$ASAIP expect "password:" send "$PWD\n" expect ">" send "en\n" expect "Password:" send "$PWD\n" expect "#" send "copy run tftp:\n" expect "Source" send "\n" expect "Address" send "$TFTP\n" expect "Destination" send "$DSTFILE\n" expect "Cryptochecksum" send "\n" send "exit\n"
Save above in a file - for example - asa-bash.sh
chmod +x asa-bash.sh
Run the shell script with arguments.
./asa-bash.sh <ASAIP> <USER> <PWD> <TFTP> <DSTFILE>
example:
./asa-bash.sh 10.10.10.10 admin Cisco123 1.1.1.1 asa-conf-backup.txt
The script expects the ssh and enable password are same. If not the same you could simply add another variable.
Appreciate it if you could hit the helpful button for any helpful posts.
05-27-2020 06:19 AM - edited 05-27-2020 06:25 AM
Try this one -
#!/usr/bin/env python from netmiko import ConnectHandler from datetime import datetime from getpass import getpass import time today = str(datetime.now().strftime('%Y-%m-%d-%H-%M')) filename = (today + "_asa_config.txt") # Device data # Replace IP below with your ASA IP address cisco_asa = { 'device_type': 'cisco_asa', 'ip': '10.45.22.20', 'username': raw_input('Enter username: '), 'password': getpass('SSH password: '), 'secret': getpass('Enable password: '), 'verbose': False, } copy_cmd = "copy running-config tftp:" tftp = raw_input('Enter TFTP server IP addr: ') net_connect = ConnectHandler(**cisco_asa) net_connect.enable() time.sleep(1) output = net_connect.send_command_timing(copy_cmd) if 'Source filename' in output: output += net_connect.send_command_timing('\n') if 'remote host' in output: output += net_connect.send_command_timing(tftp) if 'Destination filename' in output: output += net_connect.send_command_timing(filename) print output
06-22-2021 03:33 PM
I dont want to be an as.... and I was just looking for netmiko scripts since I am not very advanced in python.
But why done you just run the following : sh run | red tftp://ipadd/folder/file.txt
instead of copy run ?
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide