【发布时间】:2017-10-05 14:58:02
【问题描述】:
我需要将文件 SFTP 到服务器。密码有一个美元符号$,我需要转义它。
我尝试了可以替换的 Perl 和 sed 命令,但没有添加 $ 之后的字符串。
示例:
echo "Np4$g" | perl -pe 's/$/\\\\\$/g'
输出
Np4\\$
它应该是Np4\\$g,但g 没有被附加。
代码:
/usr/bin/expect <<EOF
set timeout -1
spawn sftp -C -oPort=$port $sftp_username@$host_name
expect "password:"
send "$password\r"
expect "sftp>"
cd $remote_dir
send "mput *.txt\r"
expect "sftp>"
send
【问题讨论】:
-
/usr/bin/expect " cd $remote_dir 发送 "mput *.txt\r" 期望 "sftp>" 发送 "quit\r" EOF