4

I've currently got a SFTP script that uploads the latest version of a file to a server via SSH which runs on a cron daily. However I always get emails like this (I changed the server to example.com fyi)

/etc/cron.daily/backup:
Connected to example.com.
Connected to example.com.

The relevant part of the script looks like this:

    sftp -o "IdentityFile=~/.ssh/backup" -q backup@example.com > /dev/null << COMMANDS
        cd weekly
    put /srv/backups/daily/$INSTANCE-$(date +%Y%m%d).tgz
    quit
    COMMANDS

It does this twice since it's in a for loop and replaces the $INSTANCE variable with two different names, thus the two Connected to example.com. messages in the cron.

I'd prefer not to print everything to /dev/null since I'd like to get errors in my email. The thing I can think of is by piping to grep and greping for error or failure or something. Is that the only possible alternative?

Any help would be great!

4

2 回答 2

2

我建议查看 loglevel 的选项:

日志级别

   Gives the verbosity level that is used when logging messages from
   ssh.  The possible values are: QUIET, FATAL, ERROR, INFO, VER-
   BOSE, DEBUG, DEBUG1, DEBUG2 and DEBUG3.  The default is INFO.
   DEBUG and DEBUG1 are equivalent.  DEBUG2 and DEBUG3 each specify
   higher levels of verbose output

我不能肯定地说这会 100% 解决您的问题,但默认值为 info(报告连接和登录失败作为常见反馈)。将日志级别移动到 FATAL 只会显示 FATAL 消息。

希望这对您有所帮助,它在 ssh_config(5) 手册页中。

于 2013-11-05T23:31:21.493 回答
0

此选项可能会有所帮助:

 -q      Quiet mode: disables the progress meter as well as warning and diagnostic messages from ssh(1).
于 2018-12-17T10:51:54.433 回答