【发布时间】:2023-03-25 04:53:01
【问题描述】:
我编写了这个小脚本,用于从远程服务器获取多个文件到我的主机:
#! /usr/bin/expect -f
spawn scp \
user@remote:/home/user/{A.txt,B.txt} \
/home/user_local/Documents
expect "password: "
send "somesecretpwd\r"
interact
这工作正常,但是当我想在文件之间创建新行时:
user@remote:/home/user/{A.txt,\
B.txt} \
我收到以下错误:
scp: /home/user/{A.txt,: No such file or directory
scp: B.txt}: No such file or directory
我试过了:
user@remote:"/home/user/{A.txt,\
B.txt}" \
得到:
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
cp: cannot stat 'B.txt}"': No such file or directory
或者这个:
"user@remote:/home/user/{A.txt,\
B.txt}" \
在开始时遇到同样的错误。
我怎样才能在多行中编写文件,但这样程序才能正常工作?我需要这个来提高所选文件的可读性。
编辑: 只将本地用户名改为user_local
【问题讨论】:
-
我建议使用
sshpass。 -
sshpass的问题是我必须为多跳传递复杂的参数(我必须至少连续使用两次 ssh)。