gpt4 book ai didi

linux - 时间 + sftp 命令脚本 : how to correctly redirect output to log file

转载 作者:行者123 更新时间:2023-12-04 19:07:51 33 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





How to redirect and append both standard output and standard error to a file with Bash

(9 个回答)


1年前关闭。




我构建了一个脚本来自动化日常的 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 标志表示在非交互式环境中运行命令。

关于linux - 时间 + sftp 命令脚本 : how to correctly redirect output to log file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64572147/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com