Sponsored Content
Top Forums Shell Programming and Scripting Bash script failed with expect on cisco routers Post 302649451 by bedomon on Thursday 31st of May 2012 10:53:22 AM
Old 05-31-2012
Question Bash script failed with expect on cisco routers

Hi all,

I use a bash script which use expect to connect throught ssh and run command on a cisco router. The ssh connection with expect work fine, but the first command on the cisco router failed,
I try to run the command in error by hand and it work fine... Smilie

the first part of the script read a config file to get user and password for ssh connection.

Code:
#!/bin/bash

export WORKDIR="/foo/bar/"

function parameter()
{
 cd $WORKDIR
 if [ -r Default.properties ]; then
          sed 's/ *\#.*//' Default.properties | egrep -v '^$' > fifo 
          while read ligne ; do    # Lecture du fichier de configuration (et suppression des commentaires).
            echo $ligne

            if echo $ligne | egrep '^[   ]*host[         ]*=[   ]*.+$' >/dev/null ; then
              host=$(echo $ligne | sed 's/^[     ]*host[         ]*=[   ]*//')
              echo $host
            elif echo $ligne | egrep '^[         ]*login[        ]*=[   ]*.+$' >/dev/null ; then
              login=$(echo $ligne | sed 's/^[    ]*login[        ]*=[   ]*//')
              echo $login
            elif echo $ligne | egrep '^[         ]*password1[     ]*=[   ]*.+$' >/dev/null ; then
              password1=$(echo $ligne | sed 's/^[         ]*password1[     ]*=[   ]*//')
              echo $password1
            elif echo $ligne | egrep '^[         ]*password2[     ]*=[   ]*.+$' >/dev/null ; then
              password2=$(echo $ligne | sed 's/^[         ]*password2[     ]*=[   ]*//')
              echo $password2
            fi
          done < fifo
          rm fifo
 fi
}

function connection
{
expect <<EOD
#!/usr/bin/expect
spawn ssh $2@$1
expect "$2@$1's password: "
send "$3\r"
expect eof
interact
EOD

expect <<EOD
#!/usr/bin/expect
spawn en
expect "Password: "
send "$5\r"
expect eof
interact
EOD


}

NEW_CONFI=$1

if [ -z "$NEW_CONFI" ]; then
  error "Veuillez indiquer le NEW_CONFI en parametre (ex: 1234)"
fi


parameter
connection $host $login $password1 $1 $password2

when I run it i get the following error :

Code:
foo01-bar> spawn en
couldn't execute "en": no such file or directory
    while executing
"spawn en"

I read the post 165501 but in my case passing argument to expect work fine, the ssh connexion is ok.

If some has any idea ..
Sorry for my bad english Smilie
 

9 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Expect/telnet/testing tacacs on a cisco

At times I find the need to test that the tacacs port 49 is open. The code below works but is painfully slow because I have to wait on the timeouts. Examples of possible responds router1#telnet 10.11.20.14 49 Trying 206.112.204.140, 49 ... Open route1#telnet 10.11.19.14 49 Trying... (1 Reply)
Discussion started by: popeye
1 Replies

3. Shell Programming and Scripting

expect in bash script

Hi, I'm writing a shell script that calls a few commands that prompt the user for two simple yes/no questions. if the answers are consistent (the first is a yes, the second is a no), what would my expect script look like? Google is only giving me answers for scripts where I telnet or ssh. right now... (3 Replies)
Discussion started by: js741
3 Replies

4. Shell Programming and Scripting

Perl Telnet cisco routers

Hi all i have little problem finding solution about simple telnet script .... i have 250 routers and on some i have different password and on some they ask just for password no username. So for example 1,2,3 have username and password (user,password) 4, and 5 have different username and password... (0 Replies)
Discussion started by: IvanMP
0 Replies

5. Shell Programming and Scripting

Expect script to show cisco configs

I know there are better ways to do this. I prefer snmp. I do not have the proper perl modules loaded on the platorm. Snmp isnt loaded on the platform. Telnet is not an option. I need to write an expect script to pull cisco equipment configs. The following code is executed once I gain... (0 Replies)
Discussion started by: popeye
0 Replies

6. Shell Programming and Scripting

Bash script with expect

Dear all Hi I want use expect in bash so that we can not use these with each other /bin/bash. With. /usr/bin/expect How can use these with on script or how can call a script from other script #!/bin/bash clear echo "================================== " echo "Enter your Esxi IP"... (3 Replies)
Discussion started by: Baber
3 Replies

7. Shell Programming and Scripting

Bash Script Locate Word Failed

I'm using CentOS 7 and I would like to know of a way to read each line and search for a specific word. For example, if it finds the word "Fail" it sends it to a variable, and pipes it to a folder on the network. What would be the best way in making this work in a Linux environment? I wrote a... (1 Reply)
Discussion started by: SysAdminRialto
1 Replies

8. UNIX for Advanced & Expert Users

Bash script + expect

im very happy to back for this forum I have servers with alias of double dns extentions: sample: servera.test.com servera.test1.com serverb.test.com serverb.test1.com I need to login to that severs and executing the set of commands if test.com failed then try to login via... (0 Replies)
Discussion started by: prakash0106
0 Replies

9. Shell Programming and Scripting

Cisco, 2 ssh logins for expect /bash

HI all i need to connect to about 900 cisco routers and switch to do some configs changes. the issue i am having is that half the devices have one set of username and password and the other half have another username and password. From expect or bash script i can ssh into a device and make... (0 Replies)
Discussion started by: quintin
0 Replies
Smokeping_probes_IOSPing(3)					     SmokePing					       Smokeping_probes_IOSPing(3)

NAME
Smokeping::probes::IOSPing - Cisco IOS Probe for SmokePing SYNOPSIS
*** Probes *** +IOSPing binary = /usr/bin/rsh # mandatory forks = 5 offset = 50% packetsize = 56 step = 300 timeout = 15 # The following variables can be overridden in each target section ioshost = my.cisco.router # mandatory iosint = Ethernet 1/0 iosuser = admin pings = 5 # [...] *** Targets *** probe = IOSPing # if this should be the default probe # [...] + mytarget # probe = IOSPing # if the default probe is something else host = my.host ioshost = my.cisco.router # mandatory iosint = Ethernet 1/0 iosuser = admin pings = 5 DESCRIPTION
Integrates Cisco IOS as a probe into smokeping. Uses the rsh / remsh protocol to run a ping from an IOS device. VARIABLES
Supported probe-specific variables: binary The binary option specifies the path of the binary to be used to connect to the IOS device. Commonly used binaries are /usr/bin/rsh and /usr/bin/remsh, although any script or binary should work if can be called as /path/to/binary [ -l user ] router ping to produce the IOS ping dialog on stdin & stdout. Example value: /usr/bin/rsh This setting is mandatory. forks Run this many concurrent processes at maximum Example value: 5 Default value: 5 offset If you run many probes concurrently you may want to prevent them from hitting your network all at the same time. Using the probe- specific offset parameter you can change the point in time when each probe will be run. Offset is specified in % of total interval, or alternatively as 'random', and the offset from the 'General' section is used if nothing is specified here. Note that this does NOT influence the rrds itself, it is just a matter of when data acqusition is initiated. (This variable is only applicable if the variable 'concurrentprobes' is set in the 'General' section.) Example value: 50% packetsize The (optional) packetsize option lets you configure the packetsize for the pings sent. Default value: 56 step Duration of the base interval that this probe should use, if different from the one specified in the 'Database' section. Note that the step in the RRD files is fixed when they are originally generated, and if you change the step parameter afterwards, you'll have to delete the old RRD files or somehow convert them. (This variable is only applicable if the variable 'concurrentprobes' is set in the 'General' section.) Example value: 300 timeout How long a single 'ping' takes at maximum Example value: 15 Default value: 5 Supported target-specific variables: ioshost The ioshost option specifies the IOS device which should be used for the ping. Example value: my.cisco.router This setting is mandatory. iosint The (optional) iosint option allows you to specify the source address or interface in the IOS device. The value should be an IP address or an interface name such as "Ethernet 1/0". If this option is omitted, the IOS device will pick the IP address of the outbound interface to use. Example value: Ethernet 1/0 iosuser The (optional) iosuser option allows you to specify the remote username the IOS device. If this option is omitted, the username defaults to the default user used by the remsh command (usually the user running the remsh command, ie the user running SmokePing). Example value: admin pings How many pings should be sent to each target, if different from the global value specified in the Database section. Note that the number of pings in the RRD files is fixed when they are originally generated, and if you change this parameter afterwards, you'll have to delete the old RRD files or somehow convert them. Example value: 5 AUTHORS
Paul J Murphy <paul@murph.org> based on Smokeping::probes::FPing by Tobias Oetiker <tobi@oetiker.ch> NOTES
IOS Configuration The IOS device must have rsh enabled and an appropriate trust defined, eg: ! ip rcmd rsh-enable ip rcmd remote-host smoke 192.168.1.2 smoke enable ! Some IOS devices have a maximum of 5 VTYs available, so be careful not to hit a limit with the 'forks' variable. Password authentication It is not possible to use password authentication with rsh or remsh due to fundamental limitations of the protocol. Ping packet size The FPing manpage has the following to say on the topic of ping packet size: Number of bytes of ping data to send. The minimum size (normally 12) allows room for the data that fping needs to do its work (sequence number, timestamp). The reported received data size includes the IP header (normally 20 bytes) and ICMP header (8 bytes), so the minimum total size is 40 bytes. Default is 56, as in ping. Maximum is the theoretical maximum IP datagram size (64K), though most systems limit this to a smaller, system-dependent number. 2.6.8 2013-03-17 Smokeping_probes_IOSPing(3)
All times are GMT -4. The time now is 05:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy