vmstat is not writing its output to the file

时间:2016-07-11 19:25:28

标签: bash unix solaris

I am trying to run vmstat via a bash script every 20 seconds and output the results to a file for several hours. My script looks like this:

#!/bin/bash
vmstat 20 1000 | ./timestamp.pl >> vmstat.txt

timestamp.pl script looks like this:

#!/usr/bin/perl

while(<>){
print localtime() . "$_ ";}

I am calling timestamp.pl to insert timestamp in each line of vmstat output. The script is running on SunOS for about an hour and I dont see any entry in vmstat.txt file. Any ideas why is this or any way to improve it so that it writes the output to the vmstat.txt file?

1 个答案:

答案 0 :(得分:2)

Either wait for enough time for the perl output to be flushed (the script will end after about 5h30min) or disable buffering in your perl script by adding this line before the loop:

$|++;