我的操作系统是虚拟机中的Ubuntu16。我正在尝试用scp编写一个脚本来传输多个文件(文件名:t01,t02,t03)。这是我的代码:
vim scriptname
#!/bin/bash
for a in {01..03}
do scp -i ~/home/username/.ssh/id_rsa -r t$a
[email protected]:/home/username/Desktop
done
当我在终端输入这个
./scriptname
我懂了
Warning: Identity file /home/ian/home/ian/.ssh/id_rsa not accessible: No
such file or directory.
t01: No such file or directory
Warning: Identity file /home/ian/home/ian/.ssh/id_rsa not accessible: No
such file or directory.
t02: No such file or directory
Warning: Identity file /home/ian/home/ian/.ssh/id_rsa not accessible: No
such file or directory.
t03: No such file or directory
我无法理解的一件事是我在剧本中写了“/home/ian/.ssh/id_rsa”。但错误消息显示“/home/ian/home/ian/.ssh/id_rsa”。我试图以不同的方式键入我的ssh_key目录,例如“/.ssh/id_rsa”,但仍无法正常工作。我做错了什么?谢谢!
t01: No such file or directory
告诉你,它无法访问该文件
因为运行bash脚本的字典与文件所在的字段不同。
如果要将文件放在同一个字典中,则必须为所有文件提供完整路径。