Search code examples
remote-accessexpectcvs

How to use CVS in expect through SSH?


I can't find a way to pass CVS the password to run it automatically on the test server. I am trying to make a expect script.

I have a ssh alias, for which I made an ssh-copy-id, so the pasword handeling of ssh is no problems.

I would like to emulate :

ssh name;
run_remote_script.sh 
#(which triggers cvs update at the good place. Nb, the server has a MOTD)
expect "Password:"
send "${CVS_REMOTE_PASSWORD}\n" #enter the password

I made that :

#!/bin/bash

SOFT=$(basename $0)

if [ -z ${CVS_REMOTE_PASSWORD+x}  ];then
    echo "$SOFT : Undefined variable \$CVS_REMOTE_PASSWORD"
fi

hostname="company"

/usr/bin/expect <<EOD
spawn ssh $hostname
cvs_company.sh
expect "Password:"
send "$CVS_REMOTE_PASSWORD\n"
interact
EOD

I would like to point out that typing ssh company, though 'company' is a placeholder, in my console works perfectly fine.

What is wrong with my script ? It yields "Invalid command name cvs_company.sh while executing cvs_company.sh"

Is there a proper way of doing that ?


Solution

  • Sounds like you need something like this:

    expect << EOD
    spawn ssh $hostname
    expect "YOUR-SHELL-PROMPT"
    send "cvs_company.sh\r"
    expect "Password:"
    send "$CVS_REMOTE_PASSWORD\r"
    interact
    EOD