0

I have a list with 950 MongoDB VMs

I wish to collect all mongodb.log. The path to log file is depending on database name.

for i in $(cat /tmp/mongonodes.txt) ; do sshpass -p34dDgdWger@rg4fll434ef scp root@$i:/data/*replicaset/*replicaset*/mongodb.log /tmp/$i-mongodb.log; done

The above command doesen't work. I can't signle quote the root@$i:/data/*replicaset/*replicaset*/mongodb.log because of variable hostname.

SSH keys are not an option.

2

Escaping SSH:

  • Consider moving data over SSH, escaping * using \ or "" (quotes). You don't need to escape the variable, just the scp host:"path\ *" for example. You may need to escape it twice.

Example, using \*:

# On server (created a test log to replicate your scenario):
mkdir -p /data/TEST1replicasetTEST2/TEST3replicasetTEST4
touch /data/TEST1replicasetTEST2/TEST3replicasetTEST4/mongodb.log

# On client (I already have ssh keys, but sshpass will work all the same):
for i in $(cat /tmp/mongonodes.txt)
do 
    scp cmihai@$i:/data/\*replicaset\*/\*replicaset\*/mongodb.log \ 
       /tmp/$i-mongodb.log
done

Result:

mongodb.log                                   100%    0     0.0KB/s   00:00

$ ls /tmp/*mongo*
/tmp/192.168.136.148-mongodb.log  /tmp/mongonodes.txt

Short term:

  • Setup SSH keys and distribute them to your servers (ex: ssh-copy-id)

Medium term:

  • Consider using configuration management software such as Ansible or Chef

Long term:

  • Look at a centralized logging (such as syslog)
  • Distributed log collectors such as Flume

Reference:

PS: don't paste your password here :-).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.