expect - read passphrase from a file
hi,
I want to rsync files into a backup server periodically. I use rsync over ssh. I use ssh-keygen to generate public-private keypair (using a passphrase) and copy the public key to the destination machine. Now when i do ssh, the rsync prompts for the passphrase. To supply it, i use the expect script. I am new to expect. I googled and found the following script. <code> #!/usr/bin/expect set timeout 19900 spawn /bin/bash expect -re "]# " send "rsync -avz -e ssh user@host:/etc/passwd /tmp/\r" expect -re "Enter passphrase" sleep 2 send "abcdefgh\r" expect -re "total size is" send "exit\r" </code> The passphrase is "abcdefgh". This works perfectly fine. But my requirement is to get this passphrase from a file instead of hardcoding inside the expect script like the following. <code> expect -re "Enter passphrase" sleep 2 send "`cat /tmp/passphrasefile`\r" </code> How can i do this. Any help is appreciated. TIA. :newbie: |
Hi hk_linux,
As you I ran into the same problem and found out the answer checking the TCL/TK manual. You have to open the file you want to `cat` with TCL commands (not shell one's) and place its contents on a variable. Then you might use this variable anytime at your script. At last, you may close the file descriptor. For example: Code:
set fp [open "/tmp/passphrasefile" r] Code:
expect "somestuff" Good luck, Eduardo Nunes |
(wow. it is 2018 and i found an answer outside of stackoverflow.com)
for the people coming here looking for how to read both username and password from file Code:
#!/usr/bin/expect -f the file logindata should look like this Code:
username |
All times are GMT -5. The time now is 10:50 PM. |