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...
the first part of the script read a config file to get user and password for ssh connection.
#!/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 :
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