0

In this script it gets the server list from file vmr.txt and after it tried to find out log files which is more than 500M and move.

I stuck here with the find redirect, I do pass the multiple output of finds to next command in side the for loop.

#!/bin/bash -x

$tdate=`date +%Y%m%d-%H%M%S`

for vm in `(cat /nodes/vmr.txt | awk '{print$2}'|| sed -e 's/[[:space:]]*$//')`
do

ssh pbc01@$vm `find /var/log/vmr/ -type f -size +500M |grep -v ".gz"`

ssh pbc01@$vm gzip -c $file > "$file"."$tdate".gz && cp -v /dev/null "$file"
ssh pbc01@$vm  mv /var/log/vmr/*.gz /vmr/oldlog/
  done
  • Could you possibly clean up the code a bit and format it properly with a 4 space indent? – Kusalananda Jul 2 '17 at 14:21
  • don't use $ when assigning variables, i.e. line 3 should be tdate=.... – drewbenn Jul 2 '17 at 15:18
0

You should avoid processing the output of ls or, equivalently here, find. Everything you're doing could be a single find command though:

ssh pbc01@"$vm" find /var/log/vmr -type f -size +500M -not -name '*gz' -exec sh -c 'gzip -c "$1" > "$1.$tdate.gz"' "" {} \; -exec truncate -s 0 {} \;

you could even have the gzip write directly to /vmr/oldlog instead of moving it after by just putting that path as part of the target of gzip

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.