Bash script (name: script.sh)
#!/bin/bash
rsync -avz username@ip:/fileineed /home
Expect script
#!/bin/expect
spawn ./script
expect “password:”
answer “pass” #i want to take answer from a file which name is password.txt
expect “$”
expect is an extension of the tcl language
To read a file, you need to open
the file, read
from the opened channel and then close
the channel.
read
by default includes the trailing newline in the result. string trim
can strip it off but read has an option to do it.
set f [open password.txt r]
set password [read -nonewline $f]
close $f
send -- "$password\r"