以下脚本旨在例如每 15 秒输出一次“vmstat”,但由于某种原因,它仅在有活动或我终止脚本时才执行此操作,在其他情况下它只是坐在那里。
#!/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 &
我猜最后的“&”符号与此有关,我这样做只是为了可以一次执行每个命令。