Sponsored Content
Top Forums Shell Programming and Scripting Expect script help needed- script failing if router unavailable Post 302523935 by mrkz1974 on Friday 20th of May 2011 10:04:37 AM
Old 05-20-2011
Expect script help needed- skipping unavailable routers?

Hey all. Sometimes I'm tasked to change some router configs for the entire network (over 3,000 Cisco routers). Most of the time its a global config parameter so its done with a loop and an IP list as its the same configuration change for all routers. This is working OK.

However, sometimes an expect script must be generated for ALL routers since the config changes are different for each router. The way we approach it, we divide the routers per regional domains (6 in total), and produce 1 expect script per regional domain. The problem I'm having is that when I schedule these type of expect scripts to run via crontab, they usually get hung anytime a router fails to respond (maintenance, outage, etc). How can I make the script go to the next router if a router cannot be reached? Here's a sample line of the 20K lines:

....
Code:
#
set timeout 10
spawn telnet 10.156.112.1
match_max 100000
expect Username:
sleep .1
send -s -- "username\r"
expect Password:
sleep .1
send -s --  "passwordstring\r"
expect *
sleep .1
send -s --  "conf t\r"
expect *
sleep .2
send -s -- "no ip flow-export destination 172.17.187.127 9995\r"
expect *
sleep .2
send -s -- "no ip flow-export destination 10.24.180.110 9995\r"
expect *
sleep .2
send -s -- "ip flow-export destination 172.17.187.188 9995\r"
expect *
sleep .2
send -s -- "ip flow-export destination 10.24.180.110 9995\r"
expect *
sleep .2
send -s -- "end\r"
expect *
sleep .4
send -s --  "wr mem\r"
expect *
sleep .2
send -s --  "exit\r"
expect eof
#
#
set timeout 10
spawn telnet 10.156.112.2
match_max 100000
expect Username:
sleep .1
send -s -- "username\r"
expect Password:
sleep .1
send -s --  "passwordstring\r"
expect *
sleep .1
send -s --  "conf t\r"
expect *
sleep .2
send -s -- "no ip flow-export destination 172.17.187.127 9995\r"
expect *
sleep .2
send -s -- "no ip flow-export destination 10.24.180.110 9995\r"
expect *
sleep .2
send -s -- "ip flow-export destination 172.17.187.188 9995\r"
expect *
sleep .2
send -s -- "ip flow-export destination 10.24.180.110 9995\r"
expect *
sleep .2
send -s -- "end\r"
expect *
sleep .4
send -s --  "wr mem\r"
expect *
sleep .2
send -s --  "exit\r"
expect eof
#
#

Thanks!
Marcos

Last edited by mrkz1974; 05-20-2011 at 11:42 AM..
 

10 More Discussions You Might Find Interesting

1. Solaris

sendto failing "resource temporarily unavailable"

Well, I am not even sure if its failing, cause at the other end I have a select call and it wakes up and reads the data I sent fine. Ok here is the issue, I have a UDP socket(non blocking) through which I push some data to another port. At the other end I have select loop, waiting for this data.... (6 Replies)
Discussion started by: Naanu
6 Replies

2. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

3. Shell Programming and Scripting

calling expect script in ksh is failing via cron

I'm calling an expect script via a ksh script in cron and it is failing. The script runs fine if i run it manually. Does anyone know if it is an issue with compatibilty and if there is a way around it? (2 Replies)
Discussion started by: bhatia
2 Replies

4. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

5. UNIX for Advanced & Expert Users

fork: Resource temporarily unavailable , server unexpectedly unavailable network connection

Solaris 10 Server refuse to connect :wall: fork: Resource temporarily unavailable , server unexpectedly unavailable network connection , refuse error, disconnect message, fatal error type2, (protocol error type2) Issue has been resolved after taken few steps :b: First of all need to check... (1 Reply)
Discussion started by: taherahmed
1 Replies

6. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

7. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

8. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

9. Shell Programming and Scripting

Expect script to save configuration from a router

Hy guys, My name is Alex, i am new here and I hope to find some answers. I am trying to run a expect script to telnet to a mikrotik router, run a command (export), and save the output of that commant to a file (outputfile.txt). The problem is that only part of the output is saved to... (2 Replies)
Discussion started by: axexandru
2 Replies

10. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies
defaultrouter(4)						   File Formats 						  defaultrouter(4)

NAME
defaultrouter - configuration file for default router(s) SYNOPSIS
/etc/defaultrouter DESCRIPTION
The /etc/defaultrouter file specifies a IPv4 host's default router(s). The format of the file is as follows: IP_address ... The /etc/defaultrouter file can contain the IP addresses or hostnames of one or more default routers, with each entry on its own line. If you use hostnames, each hostname must also be listed in the local /etc/hosts file, because no name services are running at the time that defaultrouter is read. Lines beginning with the ``#'' character are treated as comments. The default routes listed in this file replace those added by the kernel during diskless booting. An empty /etc/defaultrouter file will cause the default route added by the kernel to be deleted. Use of a default route, whether received from a DHCP server or from /etc/defaultrouter, prevents a machine from acting as an IPv4 router. You can use routeadm(1M) to override this behavior. FILES
/etc/defaultrouter Configuration file containing the hostnames or IP addresses of one or more default routers. SEE ALSO
in.rdisc(1M), in.routed(1M), routeadm(1M), hosts(4) SunOS 5.10 17 Aug 2004 defaultrouter(4)
All times are GMT -4. The time now is 06:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy