Rsync - hot to omit MOTD/banners

I'm working on an rsync script and I'd like it to omit the MOTD banners and NOT output them to the file. I tried the --no-motd argument in the command but for some reason the MOTD still continues to appear. Can anyone advise?

Not output them to what file?

#/bin/bash

command="rsync -ahvz -e ssh --delete --no-motd"
NOW=`date +%Y%m%d`
#OUTPUT=

# Command       Source Dir                              Dest Dir                                        Output
# -------       ----------                              ---------                                       -------

$command        /data/newfiles/jf-logs/                 sdc-mgmt-sr:/data/oldfiles/fj-logs/            >> /data/rsyslog/logs/rsync.log.$NOW 2>&1

it may be sshd banner, not motd.

$ ssh server1 date
Internal System. Unauthorized access is prohibited.
Mon Sep 28 17:58:16 CEST 2015

vs.

$ ssh server1 date 2>/dev/null
Mon Sep 28 17:58:20 CEST 2015

ok how do you supress the ssd banner then instead? think that is probably it

You can ask the sysadmins to put a test in to see if the process is a batch process, rather than an interactive process and to only show the message when the process is interactive. As far as I know, doing an rsync is considered a batch process on the server that it is connecting to.

I would expect an ssh banner to go to stderr, not stdout, I'm surprised >> is able to capture it. You could try --msgs2stderr but I suspect that will send more to stderr than you wanted.

Completely avoiding the ssh motd is difficult, that's something that's determined server side, not client side.

I think that the -q supresses the pre-login banner that is set in sshd_config, e.g.

Banner /etc/issue

and the --no-motd suppresses the

PrintMotd yes

If there is additional "print motd" code then the traditional suppression method is to have an (empty) .hushlogin file in the home directory on the remote server.

1 Like

ok so update: I found that the "ssh -q" variable does supress the sshd banner however when trying to do that in my command - it does not seem to work i assume because of the quotes? Can anyone point me to the correct syntax for how to make this work?

command="rsync -ahvz -e 'ssh -q' --delete" <-- this does not work because of the syntax around the ssh -q variable currently but

just doing a

rsync -ahvz -e "ssh -q" --delete /data/sourcedir/ server:/data/destdir/

from the command line does work correctly

so i guess the question is how to incorporate the ssh-q into my command statement

sorry - im a relative newbie on RHEL scripting so some of this may not come out well in my translation

You can't put quotes in quotes. Quotes don't work that way.

You shouldn't be storing entire commandlines in a variable. Variables don't work that way either, as you've discovered.

Why not use the command line for the command, and reserve variables, for things that vary?

One of the rare situations where eval should be used.

command="rsync -aHhvz -e 'ssh -q' --delete"
eval $command /data/sourcedir/ server:/data/destdir/
1 Like