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
MSSQL_FETCH_FIELD(3)													      MSSQL_FETCH_FIELD(3)

mssql_fetch_field - Get field information

SYNOPSIS
object mssql_fetch_field (resource $result, [int $field_offset = -1]) DESCRIPTION
mssql_fetch_field(3) can be used in order to obtain information about fields in a certain query result. PARAMETERS
o $result - The result resource that is being evaluated. This result comes from a call to mssql_query(3). o $field_offset - The numerical field offset. If the field offset is not specified, the next field that was not yet retrieved by this function is retrieved. The $field_offset starts at 0. RETURN VALUES
Returns an object containing field information. The properties of the object are: o name - column name. if the column is a result of a function, this property is set to computed#N, where #N is a serial number. o column_source - the table from which the column was taken o max_length - maximum length of the column o numeric - 1 if the column is numeric o type - the column type. EXAMPLES
Example #1 mssql_fetch_field(3) example <?php // Connect to MSSQL and select the database mssql_connect('MANGOSQLEXPRESS', 'sa', 'phpfi'); mssql_select_db('php'); // Send a select query to MSSQL $query = mssql_query('SELECT * FROM [php].[dbo].[persons]'); // Construct table echo '<h3>Table structure for 'persons'</h3>'; echo '<table border="1">'; // Table header echo '<thead>'; echo '<tr>'; echo '<td>Field name</td>'; echo '<td>Data type</td>'; echo '<td>Max length</td>'; echo '</tr>'; echo '</thead>'; // Dump all fields echo '<tbody>'; for ($i = 0; $i < mssql_num_fields($query); ++$i) { // Fetch the field information $field = mssql_fetch_field($query, $i); // Print the row echo '<tr>'; echo '<td>' . $field->name . '</td>'; echo '<td>' . strtoupper($field->type) . '</td>'; echo '<td>' . $field->max_length . '</td>'; echo '</tr>'; } echo '</tbody>'; echo '</table>'; // Free the query result mssql_free_result($query); ?> SEE ALSO
mssql_field_seek(3). PHP Documentation Group MSSQL_FETCH_FIELD(3)
All times are GMT -4. The time now is 09:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy