以下是一个示例Bash脚本,旨在访问远程主机上位于三层路径深度内的文件:
#!/bin/bash
# 远程主机信息
remote_host="remote_host_ip"
remote_user="remote_username"
remote_password="remote_password"
# 文件路径
file_path="/path/to/remote/file"
# SSH连接到远程主机并获取文件
sshpass -p ${remote_password} ssh ${remote_user}@${remote_host} "cat ${file_path}"
在本示例中,我们使用sshpass和ssh命令。 sshpass命令用于自动处理SSH登录所需的密码,而ssh命令用于与远程主机建立SSH连接并执行cat命令以读取文件内容。
在您的环境中,您需要替换remote_host,remote_user,remote_password和file_path以匹配您的设置。同时,请确保您的Bash脚本有足够的权限来读取文件。