Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.


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.

share|improve this question
You can change grep -v grep | grep "vmstat 15" to grep "[v]mstat 15", it is slightly safer in matching. –  jippie Dec 11 '12 at 8:01
When on Linux, you might want to check pgrep and pkill. –  jippie Dec 11 '12 at 8:03
If you do have to grep, you don't need the grep ps -ef | awk '/[v]mstat 15/{ print $2 }'. had to add it, sorry =) –  mtm Dec 11 '12 at 18:55
add comment

1 Answer

up vote 1 down vote accepted

Your perl script in the middle is probably suffering from buffering. Try the commands without the | /home/Beer/./addtimestamp.pl. If that resolves the issue try adding:

$| = 1;

to the perl script.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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