Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

up vote 3 down vote accepted

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:

--source-password
--source-username
--sync-password
--sync-username

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.

share|improve this answer
    
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.

share|improve this answer
    
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?

share|improve this answer
    
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.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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