Reputation: 3420
I have a simple script as follows which uses expect
to rsync some data (over ssh). The code is as follows:
local_path1="/root/accordingtojim.txt"
username="ih4d35"
ip="10.0.0.152"
port="22"
password="t3tr@h3dr0n"
echo "$local_path1 $username $ip $port $password"
expect -c 'spawn rsync -avz -e "ssh -p $port" $local_path1 $username\@$ip:~/; expect '*?assword:*' {send \"$password\r\"; interact};'
This is the error I get:
can't read "port": no such variable
while executing
"spawn rsync -avz -e "ssh -p $port" $local_path1 $username\@$ip:~/"
The echo
statement works fine though.
What am I doing wrong?
Upvotes: 0
Views: 492
Reputation: 2457
Shell variables aren't expanded between single quotes, so get rid of them and replace the nested quotes with escaped ones:
expect -c "spawn rsync -avz -e \"ssh -p $port\" $local_path1 $username\@$ip:~/; expect '*?assword:*' {send \"$password\r\"; interact};"
Upvotes: 3