Determine if the "yes" is necessary when doing an SCP
- by glowcoder
I'm writing a Groovy script to do an SCP. Note that I haven't ran it yet, because the rest of it isn't finished. Now, if you're doing an scp for the first time, have to authenticate the fingerprint. Future times, you don't.
My current solution is, because I get 3 tries for the password, and I really only need 1 (it's not like the script will mistype the password... if it's wrong, it's wrong!) is to pipe in "yes" as the first password attempt. This way, it will accept the fingerprint if necessary, and use the correct password as the first attempt. If it didn't need it, it puts yes as the first attempt and the correct as the second.
However, I feel this is not a very robust solution, and I know if I were a customer I would not like seeing "incorrect password" in my output. Especially if it fails for another reason, it would be an incredibly annoying misnomer.
What follows is the appropriate section of the script in question. I am open to any tactics that involve using scp (or accomplishing the file transfer) in a different way. I just want to get the job done. I'm even open to shell scripting, although I'm not the best at it.
def command = []
command.add('scp')
command.add(srcusername + '@' + srcrepo + ':' + srcpath)
command.add(tarusername + '@' + tarrepo + ':' + tarpath)
def process = command.execute()
process.consumeOutput(out)
process << "yes" << LS << tarpassword << LS
process << "yes" << LS << srcpassword << LS
process.waitfor()
Thanks so much,
glowcoder