Disclaimer:: I am not an active shell scripter

How does one create a script that responds to console output? For instance, I'm trying to setup a cron that periodically svnsync 's changes to my repository to a backup server every midnight. The problem is, in order to sync, it prompts for authorization credentials.

svnsync sync accepts no options to specify a login thus a simple cron command is out. I believe I can launch a script but I'm trying to figure out how to make it respond to console output.

For instance:

ken@server:~$ svnsync sync https://svn3.backup.net/svn/mirror
Authentication realm: <https://svn3.backup.net/svn/mirror:443> backup.net Subversion Backup
Password for 'ken':
***<send return key>***
Username:***<specify backup.net username>***
Password for '<the name>':***<specify password for username>***
<It proceeds to check out>

where ***< message >*** is the action I want the script to respond to.


I was in doubt when you said "svnsync sync accepts no options to specify a login" so I checked the documentation and guess what, it does:


Those options should be enough for you to go back to a simple cron script.

Back into the case where you really can't specify such options, it is still easy to write a wrapper script that sends data to the program's stdin. For example the following may work (where program is the program you wan to run, and text is a file where you store text to be sent to the program):

program < text

However, for authentication, programs are often written to ready from tty and not from stdin (for security reasons). I'm not familiar with it, but you can still create a fake terminal in that case. This is where expect comes into use.

  • I thought those options were specific to an option other than sync, I suppose I read wrong. Thank you clarifying my misconception and answering my misinformed question simultaneously. – Ken Feb 10 '11 at 0:36

expect might help.

There's a O'Reilly tutorial.

  • Ah yes that solves my question precisely! – Ken Feb 10 '11 at 0:33

Except this means putting passwords in clear in some script.
Not a very good idea.

Does svnsync not have options for ssh keys?

  • SSH keys won't do a lot of good if it's http authentication. – jsbillings Feb 9 '11 at 15:04

Two similar solutions:

  • expect (as given by other answers), which requires TCL.
  • pexpect, written in pure Python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.