linux - time + sftp 命令脚本:如何正确地将输出重定向到日志文件
问题描述
我构建了一个脚本来自动化日常的 ftp 下载过程。为了使其更简单,如下所示:
#!/usr/bin/env bash
time sshpass -p "mypass" sftp myuser@sftp.domain.com:/myremotepath/myfile.txt.gz /mylocalpath/myfile.txt.gz
time sshpass -p "mypass" sftp myuser@sftp.domain.com:/myremotepath/myfile2.txt.gz /mylocalpath/myfile2.txt.gz
我执行如下脚本以将输出行重定向到日志文件:
./sftp_test.sh > /mylogpath/sftp_test.log 2>1&
但它没有按预期工作。只保存像“获取 /myremotepath/myfile2.txt.gz 到 /mylocalpath/myfile2.txt.gz”这样的行。不是时间命令输出。不是其他 sftp 线路。
如果我在没有“ > /mylogpath/sftp_test.log 2>1&”部分的情况下手动执行脚本,我想完全按照我看到的那样保存输出。
我也尝试使用 tee 命令但没有成功。
我怎样才能做到这一点?
解决方案
脚本可能是这里的一个选项,所以:
script -c ./sftp_test.sh /mylogpath/sftp_test.log
-c 标志表示在非交互式环境中运行命令。
推荐阅读
- android - 使用 MVVM 的视图上未解决的参考
- antlr - 无法从对象数组加载,因为“this.decisionToDFA”为空
- docker - 来自不安全注册表的 Dockerfile
- python - tkinter 画布和 matplotlib 图形调整大小的问题
- angular - 自定义组件接收布尔变量但不更新 HTML 中的 NgIf
- c# - 更新表中的数据时,Winforms 界面冻结
- ios - 查找集合视图单元内的视图位置
- python - 缩短多头 Python 指标
- ios - 将 TOCropViewController 与 SwiftUI 接口
- javascript - 创建代表员工集合的类