mongostat 脚本
date "+%Y-%m-%d-%H:%M:%S"
错误的:
/data/mongodb/bin/mongostat -h 127.0.0.1 --port 27017 -u admin -p 'admin' --noheaders --discover |sed "s/\([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\)/${today}-\1/g;s/k\|g\|\*\|%//g;s/|/ /g;s/\([a-zA-Z]\+\):/\1 /g;/^$\|no data\|connected/d" >> /data/logs/mongostat/${today}.log
正确的:
/data/mongodb-3.0.3/bin/mongostat -h 127.0.0.1 --port 10000 -u admin -p 'admin' --authenticationDatabase admin --noheaders --discover | while read line; do today=`date "+%Y-%m-%d"`; echo $line | sed "s/\([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\)/${today}-\1/g;s/k\|g\|\*\|%//g;s/|/ /g;s/\([a-zA-Z]\+\):/\1 /g;/^$\|no data\|connected/d" >> $today.log; done;