Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 =) – Matt Dec 11 '12 at 18:55
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

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.