The following script is meant to output "vmstat" for example every 15 seconds, but for some reason it only does this if there's activity or when I kill the script, in other cases it just sits there.

#!/bin/bash
#!/bin/sh


ps -ef | grep -v grep | grep "vmstat 15" | awk '{ print $2 }' | xargs kill

ps -ef | grep -v grep | grep "iostat 15" | awk '{ print $2 }' | xargs kill

ps -ef | grep -v grep | grep "mpstat 15" | awk '{ print $2 }' | xargs kill

today=`date +%Y-%m-%d.%H:%M:%S`

find /var/log/ -name data_collection -type d -exec mv /var/log/data_collection /home/Beer/"data_collection_${today}" \;

mkdir -p /var/log/data_collection

vmstat 15 | /home/Beer/./addtimestamp.pl > /var/log/data_collection/vm_stat &
iostat 15 | /home/Beer/./addtimestamp.pl > /var/log/data_collection/ios_stat &
mpstat 15 | /home/Beer/./addtimestamp.pl > /var/log/data_collection/mp_stat &

Im guessing the '&' symbol at the end has something to do with this, I only did this so I can execute each command at once.

有帮助吗?

解决方案

Since feature requests to mark a comment as an answer remain declined, I copy the above solution here.

What is in addtimestamp.pl? It could be that it's buffering input, and not flushing every time it reads something. – Diego Basch

@DiegoBasch that's exactly correct, I just added a '$|=1;' to the Perl script now and it started to work, basically setting the it to line buffer. Ill add the answer. – I AM L

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top